I need one button to be enabled only when two other properties have been set to a value other than null. I could to this manually but I wonder if there is a way to do it using .net's Binding class. I'm using .net 4.0 working with Windows Forms.
+1
A:
Bind your Button.IsEnabled property and make use of an IMultiValueConverter...which you can then return true only when your values are not null.
<Button.IsEnabled>
<MultiBinding Converter="{StaticResource MyConverter}">
<Binding Property1 />
<Binding Property2 />
</MultiBinding>
</Button.IsEnabled>
Aaron
2010-10-23 00:37:04
Sorry I'm not using WPF. My bad.
jsoldi
2010-10-23 00:38:34
+2
A:
No I do not believe this is possible in a WinForms application. A WinForms binding is a 1 to 1 mapping between a source object and property to a data member on the target.
An easy way to work around this though is to create a 3rd property which simply does the check you are trying to make and create a binding to that property.
public object Property1 {get; set;}
public object Property2 {get; set;}
public bool Property3
{
get { return Property1 != null && Property2 != null; }
}
JaredPar
2010-10-23 01:11:36
And then I guess I need to implement a `Property1_or_Property2Changed()` function to let everyone know that it has changed so the button can update it's `Enabled` property?
jsoldi
2010-10-27 15:57:24