c# - Binding Button IsEnabled depending of the ComboBox selection -


I'm sure it's really easy, but I do not know how it happens I have a combo box and a button , And I need to enable the button only if an item is selected in the combo box, i.e. the combo box shows no element, then the button should be disabled. How can I do this?

I have tried to do the following:

  IsEnabled = "{binding element name = mycombobox, path = selected index}" />   

But this does not work, I'm using Silverlight 5.

Thank you in advance

Something in MSDN may have helped you for It suggests that you use a converter or data trigger. I have not tested it, but maybe it will work?

  & lt; window. Resources & gt; & Lt; Style x: Key = "MyButtonStyle" TargetType = "{x: type button}" & gt; & Lt; Setter Property = "Iceded" value = "true" /> & Lt; Style.Triggers & gt; & Lt; DataTrigger binding = "{binding path = selected item, element = combobox1}" value = "{x: faucet}" & gt; & Lt; Setter property = "UIElement.IsEnabled" value = "wrong" /> & Lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /Window.Resources> & Lt; Grid & gt; & Lt; Combo box name = "combo box 1" & gt; & Lt; ComboBoxItem & gt; A & lt; / ComboBoxItem & gt; & Lt; ComboBoxItem & gt; Two & lt; / ComboBoxItem & gt; & Lt; ComboBoxItem & gt; Three & lt; / ComboBoxItem & gt; & Lt; / ComboBox & gt; & Lt; Button style = "{StaticResource MyButtonStyle}" name = "myButton" content = "push me" /> & Lt; / Grid & gt;   

edit

I think Cyndy has already figured out all this, but for any future readers. ..

As mentioned in the comments, you can not trigger the data in Silverlight. You have to do a converter. There is another post that can help in a nutshell, you have to set your XML to something like this:

  & lt; Button content = "mibuton" isEnabled = "{binding selected itam, elementname = combobox1, converter = {static resource mointer}}" />   

And then in your code-back, you'll need something:

  public class MyConverter: IValueConverter {public object convert (object value, type target Type, object parameter, cultureinfo culture) {return! (Value == empty); } Public Object Convertback (Object Value, Type Type, Object Parameter, CultureInfo Culture) {New Non Imulated Expression (); }}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -