2

i have MenuItem in my WPF App:

<MenuItem Header="_Login" Click="Login_Click" Name="mi_Login">

How can i dynamically bind the IsEnabled property on my local bool var:

public bool _IsConnected
    {
        get { return this.IsConnected; }
        set { this.IsConnected = value; }
    }

?

N_A
  • 19,799
  • 4
  • 52
  • 98
derWilly
  • 455
  • 3
  • 15

1 Answers1

1

Don't forget to set the DataContext either on the main container:

<Window DataContext="{Binding Path=YourViewModelOrCodeBehindOtherwise}">    
    <MenuItem Header="_Login" Click="Login_Click" Name="mi_Login" 
        IsEnabled="{Binding _IsConnected}" >  
</Window>
Erre Efe
  • 15,387
  • 10
  • 45
  • 77
  • 1
    What do you exactly mean with YourViewModelOrCodeBehindOtherwise, can you give an example? – derWilly Sep 22 '12 at 05:12
  • I mean the name of your DataContext. It could be the name of your ViewModel if you're using MVVM or the name of your class if you're using plain old codebehind. See here for a pretty good explanation http://stackoverflow.com/a/7262322/744484 – Erre Efe Sep 22 '12 at 05:14