Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How can I Bind a DataTemplate Slider definition to the Code behind?

How can I Bind a DataTemplate Slider definition to the Code behind?

Scheduled Pinned Locked Moved WPF
wpfquestionwcfannouncementworkspace
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maycockt
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • M maycockt

      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

      A Offline
      A Offline
      Alisaunder
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • A Alisaunder

        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

        M Offline
        M Offline
        maycockt
        wrote on last edited by
        #3

        Hi, 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups