Saturday, August 31, 2013

how to access an XAML control from code

i got a textbox control that for some reason I cannot set its text propertie from code. I think because it is part of data template but not sure. is there a way to access it. here is the XAML code.


I need to change the UnitUsedTextBlock.Text . thank you



<ListView x:Name="RouteResultsListView" ItemsSource="{Binding RouteLegs}" Width="400" Height="540" HorizontalAlignment="Left" SelectionMode="None" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate >
<ListBox ItemsSource="{Binding ItineraryItems}" Height="499">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Instruction.Text}"
TextWrapping="Wrap" MaxLines="5" Width="200" />
<TextBlock Text="{Binding TravelDistance}"
Margin="10,0,0,0" />
<TextBlock x:Name="UnitUsedTextBlock" Margin="5,0,0,0" Text="km" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>



No comments:

Post a Comment