我创建了一个程序,该程序具有两个列表视图和一个用于显示第二个列表项的详细信息的面板。第一个列表视图显示类别。
第一个列表视图项是使用Observable Collection和类似的类创建的:
public class Catagory : INotifyPropertyChanged
{
private int id;
private string name;
public int ID
{
get { return id; }
set { id = value; OnPropertyChanged(); }
}
public string Name
{
get { return name; }
set { name = value; OnPropertyChanged() ;}
}
public override string ToString()
{
return this.Name.ToString();
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName]string Caller = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this,new PropertyChangedEventArgs(Caller));
}
}
/// <summary>
/// Return a list of catergory
/// </summary>
/// <returns></returns>
public static ObservableCollection<Catagory> GetCategories()
{
var cats = new ObservableCollection<Catagory>();
cats.Add(new Catagory() {id=1,name="Softwares" });
cats.Add(new Catagory() { id = 2, name = "Books" });
cats.Add(new Catagory() { id = 3, name = "Movies" });
cats.Add(new Catagory() { id = 4, name = "Learning Videos" });
cats.Add(new Catagory() { id = 5, name = "Audio" });
return cats;
}
}
在主窗口中,我用它来填充预定义项目的列表:
groups.ItemsSource= Catagory.GetCategories();
组是我的列表视图组件名称。
我想做的是通过单击组列表视图中的每个项目,第二个列表视图显示属于该类别项目的项目。但我什至不知道从哪里开始。 我想知道如何处理大量数据。 请帮助我。
XAML :
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="95*"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<!--lists-->
<ListView x:Name="groups" />
<ListView x:Name="items" Grid.Column="1" Style="{DynamicResource ItemsList}" />
<!--ToolBars-->
<StackPanel Orientation="Horizontal" x:Name="group_tools" Grid.Column="0" Grid.Row="1" Style="{StaticResource ToolBarBackground}">
<Button Content="+" Style="{StaticResource ToolBarButtons}" Click="btn_AddCategory"/>
<Button Content="-" Style="{DynamicResource ToolBarButtons}" Click="btn_RemoveFromCategory"/>
<Button Content="*" Style="{DynamicResource ToolBarButtons}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" x:Name="items_tools" Grid.Column="1" Grid.Row="1" Style="{StaticResource ToolBarBackground}">
<Button Content="+" Style="{StaticResource ToolBarButtons}"/>
<Button Content="-" Style="{DynamicResource ToolBarButtons}"/>
<Button Content="*" Style="{DynamicResource ToolBarButtons}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" x:Name="preview_pane" Grid.Column="2" Grid.Row="1" Style="{StaticResource ToolBarBackground}">
<Label FontSize="10" Foreground="Gray" FontWeight="Bold" HorizontalAlignment="Right" VerticalAlignment="Center">Version: Just UI</Label>
</StackPanel>
<!-- spliters -->
<GridSplitter Grid.Column="1" HorizontalAlignment="Left" Width="1"/>
<GridSplitter Grid.Column="2" HorizontalAlignment="Left" Width="1"/>
<!--Spliters-->
</Grid>