我正在尝试使用每行上的复选框创建一个组合框,以允许多次选择.作为用户控件或自定义控件,这会更好吗?
我之前没有创建过一个控件,只是在寻找一个关于我需要走向哪个方向的建议.
谢谢.
我正在尝试将一个TreeView放在WPF中的ComboBox中,这样当组合框被删除时,用户就会获得一个分层列表而不是一个平面列表,而他们选择的任何节点都会成为ComboBox的选定值.
我已经搜索了很多关于如何实现这个目标但是我能找到的最好的只是潜在的解决方案,因为我对WPF来说是荒谬的,我无法工作.
我对WPF和数据绑定有足够的了解,我可以将我的数据放到树视图中,甚至可以在组合框中获取树视图,但是我能够完成的任何操作都不正常.我附上了截图来说明我的意思.在屏幕截图中,组合框是"打开"的,因此底部的树视图是我可以选择节点的地方,树形视图"在顶部"正在组合框顶部绘制,我想要所选节点的文本/值在要显示的树中.
基本上我不知道怎么做的是如何让treeview的currrently选择节点将其值返回到组合框,然后组合框将其用作选定值?
这是我目前使用的xaml代码:
<ComboBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Top">
<ComboBoxItem>
<TreeView ItemsSource="{Binding Children}" x:Name="TheTree">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type Core:LookupGroupItem}" ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Path=Display}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
</ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
截图:
天儿真好!
我希望我的WPF ComboBox在其数据绑定选择时显示一些替代文本null.
视图模型具有预期的属性:
public ThingoSelectionViewModel : INotifyPropertyChanged {
public ThingoSelectionViewModel(IProvideThingos) {
this.Thingos = IProvideThingos.GetThingos();
}
public ObservableCollection<Thingo> Thingos { get; set; }
public Thingo SelectedThingo {
get { return this.selectedThingo; }
set { // set this.selectedThingo and raise the property change notification
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
该视图以预期的方式将XAML绑定到视图模型:
<ComboBox x:Name="ComboboxDrive" SelectedItem="{Binding Path=SelectedThingo}"
IsEditable="false" HorizontalAlignment="Left" MinWidth="100"
IsReadOnly="false" Style="{StaticResource ComboboxStyle}"
Grid.Column="1" Grid.Row="1" Margin="5" SelectedIndex="0">
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem IsEnabled="False">Select a thingo</ComboBoxItem>
<CollectionContainer
Collection="{Binding Source={StaticResource Thingos}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
该 …
如何使用复选框制作下拉列表?我有一个Windows应用程序(vb.net)和checkboxlist控件不是真正的选项与我的表单上的可用空间.
谢谢.