У меня есть 4 ListPickers с HeaderName (категории компьютерных аксессуаров).
- Процессор.
- материнская плата.
- RAM.
HardDrive.
Categories.XAML.CS
public Categories()
{
InitializeComponent();
this.DataContext = new manufactuers();
}
private void processorListPicker_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
processorListPicker.GetBindingExpression(ListPicker.SelectedItemProperty).UpdateSource();
}
private void motherboardListPicker_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
motherboardListPicker.GetBindingExpression(ListPicker.SelectedItemProperty).UpdateSource();
}
private void harddriveListPicker_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
harddriveListPicker.GetBindingExpression(ListPicker.SelectedItemProperty).UpdateSource();
}
private void ramListPicker_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
ramListPicker.GetBindingExpression(ListPicker.SelectedItemProperty).UpdateSource();
}
Categories.XAML
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:ListPicker x:Name="processorListPicker" Header="Processor"
ItemsSource="{Binding List1, Mode=TwoWay}"
SelectedItem="{Binding SelectedItem1, Mode=TwoWay}"
SelectionChanged="processorListPicker_SelectionChanged" Width="360" Margin="54,106,42,0" VerticalAlignment="Top" />
<toolkit:ListPicker x:Name="motherboardListPicker" Header="Motherboard"
ItemsSource="{Binding List2, Mode=TwoWay}"
SelectedItem="{Binding SelectedItem2, Mode=TwoWay}"
SelectionChanged="motherboardListPicker_SelectionChanged" Width="360" Margin="54,191,42,0" VerticalAlignment="Top" />
<toolkit:ListPicker x:Name="harddriveListPicker" Header="HardDrive"
ItemsSource="{Binding List3, Mode=TwoWay}"
SelectedItem="{Binding SelectedItem3, Mode=TwoWay}"
SelectionChanged="harddriveListPicker_SelectionChanged" Width="360" Margin="54,282,42,240" Height="85" />
<toolkit:ListPicker x:Name="ramListPicker" Header="RAM"
ItemsSource="{Binding List4, Mode=TwoWay}"
SelectedItem="{Binding SelectedItem4, Mode=TwoWay}"
SelectionChanged="ramListPicker_SelectionChanged" Width="360" Margin="54,0,42,155" VerticalAlignment="Bottom" Height="85" />
</Grid>
Manufactures.cs - ViewModel
public class manufacturers
{
public manufacturers()
{
// MUST Initialize the selected items
SelectedItem1 = "INTEL";
SelectedItem2 = "ASUS";
SelectedItem3 = "WESTERN DIGITAL";
SelectedItem4 = "CORSAIR";
}
private IEnumerable<string> manufacturersList
{
get
{
return new[]
{
"INTEL",
"AMD",
"WESTERN DIGITAL",
"CORSAIR",
"SEAGATE",
"ASUS",
"SAMSUNG",
"TOSHIBA",
"KINGSTON",
};
}
}
public IEnumerable<string> List1
{
get
{
return manufacturersList;
}
}
public IEnumerable<string> List2
{
get
{
return manufacturersList;
}
}
public IEnumerable<string> List3
{
get
{
return manufacturersList;
}
}
public IEnumerable<string> List4
{
get
{
return manufacturersList;
}
}
public string SelectedItem1 { get; set; }
public string SelectedItem2 { get; set; }
public string SelectedItem3 { get; set; }
public string SelectedItem4 { get; set; }
}
Теперь, когда пользователь нажимает на любой из этих LISTPICKERS, например, выбирает PROCESSORS-LISTPICKER, все элементы, производящие процессор, должны отображаться в элементах LISTPICKER.
Примечание. Предположим, у нас есть список производителей, которые могут быть отображены либо с помощью модели представления, либо с помощью интерактивного анализа XML или HTML.