我正在尝试将复选框添加到 WPF 中 TreeView 中的叶节点。如果我们在层次结构中有固定数量的级别并为每个级别使用 HierarchicalDataTemplate,我知道如何执行此操作。但是当我想要这个时该怎么做:
-Node 1
-- Node 1a (leaf node with checkbox)
-- Node 1b
--- Node 1bI (leaf node with checkbox)
-Node 2
-- Node 2a (leaf node with checkbox)
我将代码文件中的 DataContext 设置为 DataTable。只有一张桌子,与它本身有关。
DataContext = ds.MyDataTable;
Run Code Online (Sandbox Code Playgroud)
XAML:
<UserControl x:Class="JostyWpfControls.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="240" Width="312">
<UserControl.Resources>
<HierarchicalDataTemplate x:Key="myTemplate"
ItemsSource="{Binding myDatasetRelation}">
<CheckBox IsChecked="{Binding IsChosen}">
<TextBlock Text="{Binding Description}"/>
</CheckBox>
</HierarchicalDataTemplate>
</UserControl.Resources>
<Grid>
<TreeView x:Name="treeView"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource myTemplate}">
</TreeView>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
这是有效的,但给了我一个所有节点的检查箱。我只希望叶节点有一个复选框。
我正在尝试在Citrix服务器上使用WPF应用程序,并使用按钮和文本框创建了一个非常简单的窗口.运行应用程序时,会显示窗口顶部的应用程序名称.是不是可以在Citrix上使用WPF,还是我们的Citrix服务器太旧了?
我在使用ElementHost的WinForms中使用WPF.当表单加载时,有一个黑色背景闪烁,ElementHost即将加载.这看起来很糟糕.有关如何摆脱这个的任何建议?