I have a DataTemplate which, when referenced, displays a Slider Bar. The setup of the slider is dependant on data passed to the Form from the calling class. The XAML for the config looks like this.
<Window.Resources>
<DataTemplate DataType="{x:Type ContentControl}" x:Key="TextBoxTemplate">
<TextBox Text="{Binding ElementName=MyWindow, Path=m_csValue}" Height="23"/>
</DataTemplate>
<DataTemplate DataType="{x:Type ContentControl}" x:Key="SliderTemplate">
<Slider Name="sli" Value="{Binding ElementName = MyWindow, Path=sli}" ValueChanged="OnSliderValueChanged" IsSnapToTickEnabled="True" Margin="5" />
</DataTemplate>
<Style TargetType="{x:Type ContentControl}" x:Key="DisplayValues">
<Setter Property="ContentTemplate" Value="{StaticResource TextBoxTemplate}" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MyWindow, Path=eType}" Value="{x:Static local:eTagDisplay.Text}">
<Setter Property="ContentTemplate" Value="{StaticResource TextBoxTemplate}" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=MyWindow, Path=eType}" Value="{x:Static local:eTagDisplay.Slider}">
<Setter Property="ContentTemplate" Value="{StaticResource SliderTemplate}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid Width="267">
<StackPanel Margin="0,37,0,133" Height="123">
<TextBlock Height="23" Name="textBlock1" Text="TextBlock" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<ContentControl Style="{StaticResource DisplayValues}" Margin="12,12,12,158" />
</Grid>
In my Code Behind I set up the Max, Min, Tick Frequency and Value when the Form is created.
When the Slider bar is updated i find that the slider in the code behind is not bound to the slider on display, and so I'm not updating the value of the object I wish to update.
How can I ensure that the slider created in the XAML is bound to the slider in the code behind?
Regards
Tony