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. Can Not Bin to Dependency Property in Custom Control

Can Not Bin to Dependency Property in Custom Control

Scheduled Pinned Locked Moved WPF
wpfwcfxmlhelp
3 Posts 2 Posters 6 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
    Marc Jeeves
    wrote on last edited by
    #1

    Within my View Model i have a property and backer to bind to the ControlHideShow, I don't get a bind error but if I change the default value in the View Model nothing happens.  If I don't bind in the Implementation XAML and set Visible or Hidden it works so why can I not bind to the ViewModel thanks Madaxe

    Public interface ViewModel
    {
            Visibility ControlHideShow { get; set; }
    }
        
    public class MainPageViewModel : ViewModelBase, IMainPageViewModel
    {
        
            private Visibility _controlHideShow = Visibility.Visible;
            public Visibility ControlHideShow
            {
                get => _controlHideShow;
                set{ _controlHideShow = value;  OnPropertyChanged(nameof(ControlHideShow)); }
            }

    }

    Implementation XML

    ControlHideShow="{Binding ControlHideShow}"/>

    Custom Control XAML

    Richard DeemingR 1 Reply Last reply
    0
    • M Marc Jeeves

      Within my View Model i have a property and backer to bind to the ControlHideShow, I don't get a bind error but if I change the default value in the View Model nothing happens.  If I don't bind in the Implementation XAML and set Visible or Hidden it works so why can I not bind to the ViewModel thanks Madaxe

      Public interface ViewModel
      {
              Visibility ControlHideShow { get; set; }
      }
          
      public class MainPageViewModel : ViewModelBase, IMainPageViewModel
      {
          
              private Visibility _controlHideShow = Visibility.Visible;
              public Visibility ControlHideShow
              {
                  get => _controlHideShow;
                  set{ _controlHideShow = value;  OnPropertyChanged(nameof(ControlHideShow)); }
              }

      }

      Implementation XML

      ControlHideShow="{Binding ControlHideShow}"/>

      Custom Control XAML

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      I suspect it's because you've set the DataContext on the <UserControl> element. That means the <controls:WaitTickerControl ... ControlHideShow="{Binding ControlHideShow}" /> is binding the user control's property to itself, rather than the property from the inherited viewmodel. Try removing the DataContext assignment - you've specified the ElementName in your binding, so you shouldn't need it.

          ...
      

      If that doesn't work, try setting the DataContext on the Grid instead of the UserControl.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        I suspect it's because you've set the DataContext on the <UserControl> element. That means the <controls:WaitTickerControl ... ControlHideShow="{Binding ControlHideShow}" /> is binding the user control's property to itself, rather than the property from the inherited viewmodel. Try removing the DataContext assignment - you've specified the ElementName in your binding, so you shouldn't need it.

            ...
        

        If that doesn't work, try setting the DataContext on the Grid instead of the UserControl.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        Marc Jeeves
        wrote on last edited by
        #3

        Spot on, sometimes its the wood for the trees. thanks a bunch Madaxe

        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