Hi
I have couple of tabs with ViewModel class for each.
I want to bind the IsSelected DP to a property in the VM.
Somehow the property not updated in the view model.
I've create a demo project very simple and straightforward.
The xaml:
The code behinde:
The view model:
Any ideas?
Thanks
I have couple of tabs with ViewModel class for each.
I want to bind the IsSelected DP to a property in the VM.
Somehow the property not updated in the view model.
I've create a demo project very simple and straightforward.
The xaml:
<Grid x:Name="LayoutRoot" |
Background="White"> |
<Controls:RadTabControl> |
<Controls:RadTabItem x:Name="tab1" |
Header="tab1" |
IsSelected="{Binding Tab1 }"> |
</Controls:RadTabItem> |
<Controls:RadTabItem Header="tab2" |
x:Name="tab2" |
IsSelected="{Binding Tab2}" /> |
</Controls:RadTabControl> |
<StackPanel HorizontalAlignment="Right" |
Margin="0,0,40,0"> |
<TextBlock Text="{Binding AA}" /> |
<Button x:Name="Select" |
Content="Select Tab 1" |
Click="Select_Click" /> |
<Button x:Name="Select1" |
Content="Select Tab 2" |
Click="Select1_Click" /> |
</StackPanel> |
</Grid> |
The code behinde:
public partial class MainPage : UserControl |
{ |
public MainPage() |
{ |
InitializeComponent(); |
ViewModel = new vm(); |
} |
public vm ViewModel |
{ |
get { return DataContext as vm; } |
set { DataContext = value; } |
} |
private void Select_Click(object sender, RoutedEventArgs e) |
{ |
ViewModel.Tab1 = true; |
} |
private void Select1_Click(object sender, RoutedEventArgs e) |
{ |
ViewModel.Tab2 = true; |
} |
} |
The view model:
public class vm : INotifyPropertyChanged |
{ |
private bool _tab1; |
private bool _tab2; |
public string AA |
{ |
get |
{ |
return Tab1 ? "Tab1" : "Tab2"; |
} |
set { OnPropChanged("AA"); } |
} |
public bool Tab1 |
{ |
get { return _tab1; } |
set |
{ |
_tab1 = value; |
OnPropChanged("Tab1"); |
OnPropChanged("AA"); |
} |
} |
public bool Tab2 |
{ |
get { return _tab2; } |
set |
{ |
_tab2 = value; |
OnPropChanged("Tab2"); |
OnPropChanged("AA"); |
} |
} |
private void OnPropChanged(string propName) |
{ |
if (PropertyChanged != null) |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
} |
#region INotifyPropertyChanged Members |
public event PropertyChangedEventHandler PropertyChanged; |
#endregion |
} |
Any ideas?
Thanks