Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I've been working on this for about an hour.
My problem is very simple:
I've a listbox like
XML
<listbox istabstop="True" keyboardnavigation.tabnavigation="Continue">
 <listboxitem name="A" isenabled="{Binding EnableA}" content="aa"></listboxitem>
<listboxitem name="B" content="bb"></listboxitem>
 </listbox>



i want to switch the IsEnabled property using EnableA in the viewmodel..

thanks in advance for any help...
Posted
Updated 12-Sep-11 22:12pm
v6
Comments
Wayne Gaylard 13-Sep-11 4:00am    
Whats the problem ? I assume EnableA is a bool Property, which implements INotifyPropertyChanged. Then the binding should work as is.
CGN007 13-Sep-11 4:14am    
yes its a bool Property and implements the INotifyPropertyChanged.
private bool enableA ;
public bool EnableA
{
get { return enableA ; }
set
{
enableA = value;
this.OnPropertyChanged("EnableA");
}
}
But the ListBoxItem is always disabled.
Initially me set EnableA =true; But Stil the ListBoxItem is disabled.
Wayne Gaylard 13-Sep-11 4:23am    
Well the problem is not there, as the declaration of the property and the xaml are correct. Have you checked to see that the form's DataContext is set properly? That is all I can see that might be the issue. Are the other bindings working correctly ?
CGN007 13-Sep-11 4:35am    
Yes DataContext is properly set to the viewmodel.
public testView(INavigationViewModel model, IEventAggregator eventaggricator)
{
InitializeComponent();
this.DataContext = model;
this.eventaggricator = eventaggricator;
}

All binding in that form have the same problem.

I think your problem lies in your form constructor. you need to instantiate the viewmodel using the new syntax. It should be something like this:-

public testView(INavigationViewModel model, IEventAggregator eventaggricator) 
            { 
                InitializeComponent(); 
                model viewModel = new model();
                this.DataContext = viewModel;
                this.eventaggricator = eventaggricator; 
            } 


Hope this helps
 
Share this answer
 
Comments
CGN007 13-Sep-11 4:57am    
Here the model is the object of INavigationViewModel interface..
so can't use the code below
model viewModel = new model();
Wayne Gaylard 13-Sep-11 5:11am    
Ah, my mistake. Then you are going to have to check whether the viewmodel passed to the constructor is initialised properly. Put a breakpoint in the code at the beginning of the constructor after InitializeComponent(), and check whether the properties in the model all have valid values.
CGN007 13-Sep-11 5:49am    
All properties in the model all have valid values...
Still the problem remains unsolved...
ListBox is an Items container. so I usually set up an ObservableCollection of Models in the ViewModel; each Model has INotifyPropertyChanged for each bound property; and the Listbox is bound to the ObservableCollection using an ItemTemplate to format the displaying of each Model.

Then it is just a matter of toggling the appropriate Model's boolean property and the corresponding ListBoxItem Enabled state will change if correctly bound.
 
Share this answer
 

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