Sunday 15 July 2012

wpf - how to disable a button when a textbox becomes readonly? -


I have a button and text box inside the stackpanel, when the text box is read-only, the button should be disabled I want to do something like this in XAMML? Defining the binding is easy, but you need a converter to reverse the bullion value.

isEnabled = true ) ( IsReadOnly = false ).

XAML

  & lt; StackPainel & gt; & Lt; StackPanel.Resources & gt; & Lt; Local: InvertibleConverterX: Name = "InboundBonConverter" /> & Lt; /StackPanel.Resources> & Lt; Text Box X: Name = Text Box / & gt; & Lt; Button IsEnabled = {binding IsReadOnly, ElementName = textbox, converter = {static resource invertballcounter}} /> & Lt; / StackPanel & gt;   

local is a namespace that you define in your userstrate which points to the namespace of the inbuidonian converter

  Xmlns: local = "public class invertible converter: type public type convert (type object type, typed type, type, type, type, type, type)., Object parameter, system globilization. Culture info kalch ) {Bool currentValue = System.Convert.ToBoolean (value); Return! Current;} Public Object Convertback (Type object value, Type type, object parameter, System globalization. Cultural info culture) {bool currentValue = System.Convert. ToBoolean (value); Return! Current;}}    

No comments:

Post a Comment