I have a DataTemplate which is binded to Grid Group Header Section. There are four TextBlock in DataTemplate from one of TextBlock contains the Grid Header Column Value. Now, I want to Split this TextBlock Value into three and assign this value to other three TextBlock from Code Behind. Is it Possible?
<DataTemplate x:Key="descriptionHeader">
<!--<dxg:GroupGridRowContent>
<TextBlock Background="Yellow" Text="{Binding DisplayText}" ></TextBlock>
</dxg:GroupGridRowContent>-->
<Border BorderBrush="Black" BorderThickness="1" Width="1300">
<StackPanel Orientation="Vertical" Margin="2">
<TextBlock Name="txtdescription" Text="{Binding DisplayText}" Width="200" HorizontalAlignment="Left" ></TextBlock>
<StackPanel Orientation="Horizontal" Margin="2" Height="80">
<Image Source=".\Images\description_img.png" Stretch="None" FlowDirection="LeftToRight" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="1"/>
<StackPanel Orientation="Vertical" Margin="2">
<TextBlock Name="txtdesc1" Margin="2" FlowDirection="LeftToRight" Text="{Binding Path=GlassType,RelativeSource={RelativeSource Self}}" TextWrapping="Wrap" />
<TextBlock Name="txtdesc2" Margin="2" FlowDirection="LeftToRight" Text="{Binding Path=(dxg:RowData.RowData).GroupSummaryData[3].Text, RelativeSource={RelativeSource Self}}" TextWrapping="Wrap" />
<TextBlock Name="txtdesc3" Margin="2" FlowDirection="LeftToRight" Text="{Binding Path=(dxg:RowData.RowData).GroupSummaryData[4].Text, RelativeSource={RelativeSource Self}}" TextWrapping="Wrap" />
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</Window.Resources>
<dxg:GridControl Name="grdInfill" Height="700" VerticalAlignment="Top" >
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="GlassType" AllowEditing="False" />
<dxg:GridColumn FieldName="GlassDescription" GroupValueTemplate="{StaticResource descriptionHeader}">
<!--GroupValueTemplate="{StaticResource descriptionHeader}"-->
<!--Header="GlassDescription" DisplayMemberBinding="{Binding Path=RowData.Row.GlassDescription, Mode=TwoWay}"-->
</dxg:GridColumn>
<dxg:GridColumn FieldName="GlassType" AllowEditing="False" />
<dxg:GridColumn Name="qty" Header="Quantity" AllowEditing="False" DisplayMemberBinding="{Binding Path=RowData.Row.Quantity, Mode=TwoWay}" /> <!--FieldName="Quantity"-->
<dxg:GridColumn FieldName="Width" AllowEditing="False" Header="Length"/>
<dxg:GridColumn FieldName="Height" AllowEditing="False"/>
<dxg:GridColumn FieldName="Elevation" AllowEditing="False"/>
<dxg:GridColumn FieldName="Mark" AllowEditing="False"/>
<dxg:GridColumn FieldName="GlassTag" AllowEditing="False"/>
<dxg:GridColumn FieldName="WallLocation" AllowEditing="False"/>
<dxg:GridColumn FieldName="SquareFoot" AllowEditing="False"/>
<dxg:GridColumn FieldName="Weight" AllowEditing="False"/>
<dxg:GridColumn FieldName="UnitCost" AllowEditing="False"/>
<dxg:GridColumn FieldName="TotalCost" AllowEditing="False"/>
<dxg:GridColumn FieldName="FuelSurcharge" AllowEditing="False"/>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView ShowTotalSummary="True" AutoWidth="True" DetailHeaderContent="True" ShowIndicator="False" ShowGroupPanel="False"><!--GroupRowTemplate="{StaticResource descriptionHeader}"-->
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
protected void GetAllInfills()
{
List<Infill> infillList = new List<Infill>();
infillList=BLL.GetAllInfills();
if (infillList != null)
{
grdInfill.ItemsSource = infillList;
grdInfill.GroupBy(grdInfill.Columns["GlassType"], ColumnSortOrder.Ascending);
grdInfill.GroupBy(grdInfill.Columns["GlassDescription"], ColumnSortOrder.Ascending);
grdInfill.AutoExpandAllGroups = true;
}
}
From Above marukup i want to access the TextBlock Control i.e 'txtdescription
' which contains the group header section value of Grid Column 'GlassDescription'
now i want to split this value int to three value i.e txtdescription.Split('*') and assign values to other three textblock i.e txtdesc1,txtdesc2,txtdesc3 that are in DataTemplate from code behind.
Since you requested a sample, I am providing a sample using ListBox.
XAMLCodeBehind
EDIT in response to additional information
In WPF you can use Element Binding which allows you to access any property of a given element. Since you want to access txtdescription textblock's text property, you will have to use the Element Binding. But you wan't to split that into three TextBlocks. So you will need a converter.
Use the code below for element binding
And here is the converter code
Finally Include Converter Namespace in xaml