I am writing a Windows Phone 8.1 (WINRT) App.
I have a listbox with datatemplate. Inside datatemplate, i have a grid and a textblock. How to set the width of grid or textblock from c#?
I tried using DependencyObject VisualTreeHelper methods from internet but its not working.
XAML:
<SemanticZoom x:Name="CategorySemanticZoom"
IsZoomOutButtonEnabled="True"
CanChangeViews="True"
Grid.Row="1">
<SemanticZoom.ZoomedInView>
<ListView x:Name="Category_ListViewDetail" IsSwipeEnabled="True" IsTapEnabled="True"
IsItemClickEnabled="True"
IsZoomedInView="True"
ItemClick="Category_ListViewDetail_ItemClick" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid x:Name="SubCategoryName_grid"
x:FieldModifier="public"
>
<TextBlock
Text="{Binding SubCategoryName}"
x:Name="SubCategoryName_TextBlock"
FontSize="26"
Margin="30,0,10,0"
TextTrimming="CharacterEllipsis"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Border Background="{StaticResource DefaultTheme_DarkBlueColor}"
CornerRadius="6"
HorizontalAlignment="Left"
Margin="10,20,10,20"
Tapped="Border_Tapped"
VerticalAlignment="Center">
<TextBlock Text="{Binding CategoryName}"
/>
</Border>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical"
Margin="0 0 0 0"
ItemHeight="55"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</SemanticZoom.ZoomedInView>
<SemanticZoom.ZoomedOutView>
<ListView x:Name="Category_ListViewSummary"
Background="LightGray"
IsZoomedInView="False"
Opacity=".85">
<ListView.ItemTemplate>
<DataTemplate>
<Border Background="{StaticResource DefaultTheme_DarkBlueColor}"
CornerRadius="6"
HorizontalAlignment="Left"
Margin="10,10,10,10" >
<TextBlock Text="{Binding Group.CategoryName}"
/>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</SemanticZoom.ZoomedOutView>
</SemanticZoom>
How to set width of SubCategoryName_grid or SubCategoryName_TextBlock from C#?