【发布时间】:2019-05-22 10:15:49
【问题描述】:
我在 WPF 中使用 Kendo Telerik RadTreeview 控件。我的功能是为每个 RadTreeViewItem 节点添加一个自定义按钮,该按钮会在命令事件显示时弹出。
我已添加按钮并在HierarchicalDataTemplate 中使用它,如下所示
<HierarchicalDataTemplate x:Key="BuildingStructure"
ItemsSource="{Binding Levels, Mode=TwoWay}"
ItemContainerStyle="{StaticResource levelNodeStyle}">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Width="250"
Text="{Binding StructureName , Mode=TwoWay}"
HorizontalAlignment="Left"
Panel.ZIndex="2"/>
<Button
Canvas.Left="10"
Canvas.Bottom="20"
Panel.ZIndex="1"
BorderThickness="0"
BorderBrush="Transparent"
Background="Transparent"
Foreground="White"
HorizontalAlignment="Left"
Grid.Column="1"
VerticalAlignment="Stretch"
Command="{Binding DataContext.AddLevelRadTreeCommand, RelativeSource={RelativeSource AncestorType=telerik:RadTreeView}}"
CommandParameter="{Binding ElementName=radTreeView}"
Margin="0 2 0 5">
<Image
Width="20"
Height="20"
Source="/Project;component/Resources/Images/03-Add.png"/>
</Button>
</Grid>
</HierarchicalDataTemplate>
我想要的是在命令事件中我需要添加命令参数,该参数将传递当前分配给该节点的 RadTreeviewItem 数据对象,如下所示
StructId:1,
StructName:'Building A'....and so on...
【问题讨论】:
-
你的意思是树视图项的数据上下文?绑定datacontext relativesource self
-
@Andy 我是 wpf 的新手,以及 wpf 的 Telerik .. 我可以知道如何将当前项目传递给命令参数
-
@Andy 我可以知道我们如何传递参数
标签: wpf events telerik radtreeview custom-button