Click here to Skip to main content
12,951,619 members (59,553 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
Top Experts
Last 24hrsThis month
OriginalGriff 6,229
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100