I am working on wpf mvvm pattern.
<Grid>
<Grid.Resources>
<DataTemplate x:Key="checkboxHeaderTemplate">
<CheckBox IsChecked="{Binding Path=DataContext.AllSelected,RelativeSource={RelativeSource AncestorType=UserControl },Mode=TwoWay}">
</CheckBox>
</DataTemplate>
<DataTemplate x:Key="CheckBoxCell">
<CheckBox Command="{Binding Path=ContentWindow}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" >
</CheckBox>
</DataTemplate>
<DataTemplate x:Key="TextCell">
<TextBlock Text="Usecasename">
</TextBlock>
</DataTemplate>
<DataTemplate x:Key="ButtonCell">
<Button Content="{Binding Path=UsecaseName, Mode=TwoWay}" >
</Button>
</DataTemplate>
</Grid.Resources>
<ListView ItemsSource="{Binding Path=UsecaseListItems}" >
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn HeaderTemplate="{StaticResource checkboxHeaderTemplate}"
CellTemplate="{StaticResource CheckBoxCell}" Width="auto">
</GridViewColumn>
<GridViewColumn HeaderTemplate="{StaticResource TextCell}"
CellTemplate="{StaticResource ButtonCell}" Width="auto">
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Grid>
The HomeViewModel is like this(CCS01ViewModel) is one of the ViewModels whose View I want to load as a UseControl in my main view :
private CCS01ViewModel _ccs01Viewmodel;
public CCS01ViewModel CCS01Control
{
get { return _ccs01Viewmodel; }
set
{
if (value == _ccs01Viewmodel)
return;
_ccs01Viewmodel = value;
OnPropertyChanged("CCS01Control");
}
}
private UserControl _content;
public UserControl ContentWindow
{
get { return _content; }
set
{
_content = value;
OnPropertyChanged("ContentWindow");
}
}
private ObservableCollection<UseCase> _usecaseListItems = new ObservableCollection<UseCase>();
public ObservableCollection<UseCase> UsecaseListItems
{
get { return _usecaseListItems; }
set {
_usecaseListItems = value;
OnPropertyChanged("UsecaseListItems");
}
}
private bool _AllSelected;
public bool AllSelected
{
get { return _AllSelected; }
set
{
_AllSelected = value;
foreach (var reportListItemModel in UsecaseListItems)
{
reportListItemModel.IsSelected = this._AllSelected;
}
OnPropertyChanged("AllSelected");
}
}
The main view with which now I am just trying to bind the default one is like this:
<StackPanel>
</UserControl>-->
<ContentControl Content="{Binding CCS01Control}" />
</StackPanel>
Please suggest how can I bind my checkboxes properly so that on check of that, the respective UserControls get loaded in my main view?? Also, Will I have to create ViewModels for all the userControls I have for each checkbox?? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire