WPF - Binding IsEnabled property doesnt evaluate until DataContext

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VG9kZCBCZWF1bGlldQ==?=

    WPF - Binding IsEnabled property doesnt evaluate until DataContext

    I have a "Save Changes" button on the form. I'm binding its IsEnabled
    property to a property of the object that I'm dealing with. When I connect
    the panel the buttons are in with an object (set the DataContext when the
    user selects an object from a list), the buttons correctly evaluate. When I
    tweak the property in the object, the notification is correctly evaluated and
    the button's state changes as expected.

    When I first load the form, however, the button is enabled. Setting the
    DataContext to null on window load doesn't do the trick. Is there a way
    around this, or do I need to set the property to Disabled and then use a data
    trigger to flip it when the property goes positive? Surely, the simple
    binding is attractive, but only if I can get to work.
  • =?Utf-8?B?VG9kZCBCZWF1bGlldQ==?=

    #2
    RE: WPF - Binding IsEnabled property doesnt evaluate until DataContext

    I solved the problem by using a custom converter. I think it's strange that
    if the data source is null, the binding evaluates to true, but the converter
    solves the problem by checking if the bound object is null, and if so
    returning false.

    "Todd Beaulieu" wrote:
    I have a "Save Changes" button on the form. I'm binding its IsEnabled
    property to a property of the object that I'm dealing with. When I connect
    the panel the buttons are in with an object (set the DataContext when the
    user selects an object from a list), the buttons correctly evaluate. When I
    tweak the property in the object, the notification is correctly evaluated and
    the button's state changes as expected.
    >
    When I first load the form, however, the button is enabled. Setting the
    DataContext to null on window load doesn't do the trick. Is there a way
    around this, or do I need to set the property to Disabled and then use a data
    trigger to flip it when the property goes positive? Surely, the simple
    binding is attractive, but only if I can get to work.

    Comment

    Working...