c# - 如何在 Dropbox 中添加子项
问题描述
我有一个未完成的项目,我的第一步是修改基于组合框的主菜单,看起来像 GitHub 桌面应用程序
所以现在的任务是将相似的项目分组到子组中。
例如,日志视图、城市视图和商店视图应放在管理组下。2017...2020 年应归为一组。
不幸的是我找不到这个任务的解决方案,也许 ComboBox 不是最好的解决方案。也许有人可以告诉我我的解决方案在哪里?当嵌套项目出现在组的右侧时,它可以是可折叠组或类似菜单样式。
PS管理和年表管理只是空的组合框项目。
解决方案
所以,我的解决方案是基于他们https://stackoverflow.com/a/3585244/7283900
我在我的 ComboBox 中添加了 Expander,所以整个解决方案现在看起来像
XAML:
<Window x:Class="WpfApp1_TEST.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1_TEST"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid>
<Grid.Resources>
<Style x:Key="GroupItem" TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander x:Name="expander"
ExpandDirection="Down">
<Expander.Header>
<DockPanel>
<TextBlock Text="{Binding Name}" FontWeight="Bold" Margin="2,5,0,2" FontSize="14"/>
</DockPanel>
</Expander.Header>
<Expander.Content>
<Border Margin="5,0,0,0">
<ItemsPresenter >
</ItemsPresenter>
</Border>
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<ComboBox Height="27" HorizontalAlignment="Left"
ItemsSource="{Binding Item}"
Margin="162,109,0,0" VerticalAlignment="Top"
Width="195" Name="cboGroup" >
<ComboBox.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupItem}"/>
</ComboBox.GroupStyle>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</Grid>
以及此页面的 CodeBehind
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<Item> items = new List<Item>();
items.Add(new Item() { Name = "Item1", Category = "Category_1" });
items.Add(new Item() { Name = "Item2", Category = "Category_1" });
items.Add(new Item() { Name = "Item3", Category = "Category_1" });
items.Add(new Item() { Name = "Item4", Category = "Category_2" });
items.Add(new Item() { Name = "Item5", Category = "Category_2" });
ListCollectionView lcv = new ListCollectionView(items);
lcv.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
//this.comboBox.ItemsSource = lcv;
this.cboGroup.ItemsSource = lcv;
}
public class Item
{
public string Name { get; set; }
public string Category { get; set; }
}
}
推荐阅读
- python-3.x - 使用 tensorflow 提高 GPU 利用率
- c# - 使用存储过程同时更新和创建(多个)MVC模型
- architecture - 一些用户享受终身免费计划。我应该在支付网关中创建免费产品还是将他们的数据保留在外面?
- c++ - 将元素分配给函数类型向量的问题(作为对象的函数)
- python - tf.scatter_nd_update 不断给我一个 AttributeError
- javascript - 如何在 Angular 中处理 RxJS Observables 的异步特性
- python - 如何获取坐标?(tensorflow标签模型物体检测)
- python - Python合并变量
- typescript - Eslint --fix 移除类型注解
- python - 反复保存Conv2D(tensorflow)的结果,覆盖同一个变量