How can I Bind a DataTemplate Slider definition to the Code behind?
-
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.
<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>
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
-
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.
<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>
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
In my project I have this xaml code for my slider
My code Behind this is
// preparing tab content slider transformation
ScaleTransform scaleTransform = new ScaleTransform();
Binding scaleXBinding = new Binding("Value");
scaleXBinding.Source = scaleSlider;
Binding scaleYBinding = new Binding("Value");
scale -
In my project I have this xaml code for my slider
My code Behind this is
// preparing tab content slider transformation
ScaleTransform scaleTransform = new ScaleTransform();
Binding scaleXBinding = new Binding("Value");
scaleXBinding.Source = scaleSlider;
Binding scaleYBinding = new Binding("Value");
scaleHi, Thanks for your response, I've only just managed to pick this up. I've looked at your code sample, many thanks. The issue that I'm seeing is that using the "Name" declared for the Slider, I cannot use it in my CodeBehind without declaring an independent Slider object - which creates and new object and doesnt bind to the declared Slider in the XAML. As the Slider is named and delcared in a the section, and as part of a , do I need to reference by more than just the object name, e.g. would I need to call it something like someItem.sli as opposed to just sli? Regards Tony