Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear all,
I have following button
XAML
<Button x:Name="btnNew" Content="*"  Grid.Column="0" Click="btnNew_Click" />

and an object in runtime naming "currentObject"
the the bases of its type I am to decide wheather to enable the button or not.
I want this logic
C#
if(currentObject is Inewable)
 btnNew.IsEnabled= true;
else
btnNew.IsEnabled= false;


I want to do this in xaml rather than csharp code through Binding
Can you help how to do this.
Regards
Posted

1 solution

Bind IsEnabled property of button to your object over a ValueConverter. See
http://www.wpftutorial.net/ValueConverters.html[^]

Is it clear or do you need more information?
 
Share this answer
 
v2
Comments
Francisco T. Chavez 11-Apr-13 16:57pm    
stibee is right, doing this the WPF way would require you to build a converter class, instantiate it, and then reference it in your binding. I guess, you could also create a bool type property and bind to that, but you would still end up setting that bool type property in code the same way you are setting the IsEnabled property for the button. And, I've had issues with using bindings with the IsEnabled property, it works fine on some controls, but not on all controls.

I think your in-code solution may be the optimal solution in this case. The only thing I would change is that I would set the IsEnabled property with the result of the 'is' operator, but that's more about my own personal preferences.
stibee 11-Apr-13 17:09pm    
Thanks Francisco, you have right. I corrected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900