WPF - Binding IsEnabled property doesnt evaluate until DataContext

T

Todd Beaulieu

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.
 
T

Todd Beaulieu

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top