I'm trying to obtain the value that is returned by "condition" so the idee is to use the textblocks name in an if statement so I can change the source of an image.
when I try to do it with an textblock thats outside of the datatemplate all goes wel.. but as soon as I choose an textblock thats inside the datatemplate I get an error saying that the textblock doesnt exist. I need to do it cause when the weather changes I need another image to go with it.
xaml:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="99" >
<Grid Height="100">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=condition}" Grid.Column="1" Margin="10,75,10,0" Name="hulpBlock"></TextBlock>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
xaml.cs:
if (hulpBlock.Text == "Partly Cloudy")
{ weatherframe.Source = (ImageSource)new ImageSourceConverter().ConvertFromString("WeatherIcons/03.png"); }
In order for your weatherframe.Source to be updated, you would have to subscribe to the changed event on the Text Property of your TextBlock. A more elegant way to do it is to implement
weatherframe.Source
as a Dependency Property if it isn't already, then you can just bindcondition
toweatherframe.Source
with the appropriateValue Converter
directly.Your
ValueConverter
should look something similar to this:Then in your XAML:
In your resources section:
In your GUI: