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. DependencyProperty Binding Problem

DependencyProperty Binding Problem

Scheduled Pinned Locked Moved WPF
wpfhelpcsharpwcfcom
1 Posts 1 Posters 1 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.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I have a UserControl on a TabView that has a DependencyProperty of type Project. Project is an object.

    public static readonly DependencyProperty ProjectProperty =
    DependencyProperty.Register("Project",
    typeof(ProjectEntity),
    typeof(PurchaseOrderView),
    new PropertyMetadata(null, new PropertyChangedCallback(OnProjectChanged)));

    public ProjectEntity Project
    {
    get { return (ProjectEntity)GetValue(ProjectProperty); }
    set { SetValue(ProjectProperty, value); }
    }

    private static void OnProjectChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
    PurchaseOrderView control = (PurchaseOrderView)d;
    control.LoadPurchaseOrders();
    }
    #endregion

    When the control is first loaded, and the binding occurs, Project is set to the instance, and everything works fine. However, when I select another tab, the control's CTOR and DP's Changed method fire AGAIN and now Project is Null and casues null ref exceptions. I'm not really sure what's going on. Is it unbinding somehow?? I don't really know how to diagnose this. I found [this article](https://stackoverflow.com/questions/3601125/wpf-tabcontrol-preventing-unload-on-tab-change) that discusses the Tab Control removing and replacing its content when the tabs change, and I tried using the solution, but it doesn't work. Anyone have an ideas?

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    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