I have the following XAML markup, in which I am embedding a couple of <Image>
tags inside a <StackPanel>
, inside a <Grid>
, inside a <ControlTemplage>
:
<Window.Resources>
<Style...>
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid ...>
...
<StackPanel Grid.Row="1" Orientation="Horizontal" FlowDirection="RightToLeft">
<Image x:Name="connectedFlag" ... />
<Image x:Name="disconnectedFlag" ... />
</StackPanel>
</Grid>
</ControlTemplate>
</Setter>
</Setter>
</Style>
</Window.Resources>
I can see in the preview window in Visual Studio that these images are displayed correctly inside the <Grid>
in the <ControlTemplate>
on my GUI, however, I now want to access the images from inside my C#, so that I can call functions to show/ hide the images depending on whether my application is connected to a server or not.
I have a continuousThread()
method in my C#, in which I am trying to set the Visibility
property of connectedFlag
& disconnectedFlag
depending on which condition is met, i.e.
if(condition){
disconnectedFlag.Visibility = Visibility.Visible;
connectedFlag.Visibility = Visibility.Hidden;
}else{
disconnectedFlag.Visibility = Visibility.Hidden;
connectedFlag.Visibility = Visibility.Visible;
}
However, I get a couple of compile errors in my C# that say:
The name 'disconnectedFlag' does not exist in the current context The name 'connectedFlag' does not exist in the current context
Why can't I reference my 'flag' variables from inside the .xaml.cs
file? Anyone have any suggestions?