У меня есть представление, в котором есть главный комбинированный список, который, когда пользователь выбирает элемент, обновляет все дочерние комбинированные списки с выбранным значением.Цель состоит в том, чтобы позволить пользователю либо изменить все отрасли / владельцев файла одновременно, либо иметь возможность индивидуально изменить отрасль / владельца файлов, используя дочерний выпадающий список.
Я создал событие в модели представления для прослушивания основного изменения, но как мне обновить дочерние списки?Дочерние выпадающие списки вложены в ListView.
XAML
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="IndustryWidth"/>
<ColumnDefinition x:Name="OwnerWidth"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label HorizontalAlignment="Center" VerticalAlignment="Bottom">Master Industry</Label>
<ComboBox x:Name="MasterIndustry" Grid.Row="1" VerticalAlignment="Bottom" SelectedItem="{Binding SelectedObjectIndustry}">
<ComboBoxItem Content="HVAC"></ComboBoxItem>
<ComboBoxItem Content="Plumbing"></ComboBoxItem>
<ComboBoxItem Content="Roofing"></ComboBoxItem>
<ComboBoxItem Content="Electrician"></ComboBoxItem>
</ComboBox>
<Label Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Bottom">Master Owner</Label>
<ComboBox x:Name="MasterOwner" Grid.Column="1" Grid.Row="1" VerticalAlignment="Bottom" SelectedValue="{Binding SelectedObjectOwner}" SelectedValuePath="Content">
<ComboBoxItem Content="Jason"></ComboBoxItem>
<ComboBoxItem Content="Mike"></ComboBoxItem>
<ComboBoxItem Content="Keri"></ComboBoxItem>
</ComboBox>
</Grid>
<ListView x:Name="FileListView" ItemsSource="{Binding Files, Mode=OneWay}" Background="LightBlue" Margin="5" Grid.Row="1" HorizontalAlignment="Stretch">
<ListView.View>
<GridView>
<GridViewColumn Header="File Name" DisplayMemberBinding="{Binding FileName}" />
<GridViewColumn Header="Industry" Width="Auto" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Width="100" HorizontalAlignment="Right" >
<ComboBoxItem Content="HVAC"></ComboBoxItem>
<ComboBoxItem Content="Plumbing"></ComboBoxItem>
<ComboBoxItem Content="Roofing"></ComboBoxItem>
<ComboBoxItem Content="Electrician"></ComboBoxItem>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Owner" Width="auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="IndividualOwner" Width="100" HorizontalAlignment="Right" SelectedItem="{Binding SelectedIndividualOwner}">
<ComboBoxItem Content="Jason"></ComboBoxItem>
<ComboBoxItem Content="Mike"></ComboBoxItem>
<ComboBoxItem Content="Keri"></ComboBoxItem>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</UserControl>
Просмотр модели
Помимо LoadFileView ()Я не уверен, что мне следует делать с тем, как связать элемент управления IndividualOwner с главным элементом управления.
public FileViewModel()
{
LoadFileView();
}
private void LoadFileView()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;
openFileDialog.Filter = "CSV Files (*.CSV)|*.CSV|All Files (*.*)|*.*";
if (openFileDialog.ShowDialog() == true)
{
foreach (string file in openFileDialog.FileNames)
{
Files.Add(new FileModel(file));
}
}
}
public BindableCollection<FileModel> Files { get; set; } = new BindableCollection<FileModel>();
private string _selectedObjectIndustry;
public string SelectedObjectIndustry
{
get
{
return _selectedObjectIndustry;
}
set
{
if (_selectedObjectIndustry == value)
{
return;
}
_selectedObjectIndustry = value;
}
}
private string _selectedObjectOwner;
public string SelectedObjectOwner
{
get
{
return _selectedObjectOwner;
}
set
{
if (_selectedObjectOwner == value)
{
return;
}
_selectedObjectOwner = value;
MasterSelectionUpdate();
}
}
public string SelectedIndividualOwner
{
get
{
return _selectedObjectOwner;
}
set
{
if (_selectedObjectOwner == value)
{
return;
}
_selectedObjectOwner = value;
NotifyOfPropertyChange(() => SelectedIndividualOwner);
}
}