Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XAML WPF
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
Posted 10-Dec-12 5:01am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 239
1 Sarvesh Kumar Gupta 185
2 George Jonsson 154
3 ArunRajendra 144
4 Richard MacCutchan 140


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid