【发布时间】:2011-01-20 11:41:23
【问题描述】:
我有一个放在用户控件中的控件,它公开了一个带有 DepenceyPropety(ShowCommand) 的 ICommand, 然后我有一个带有几列的数据网格(wpf 工具包),其中一个有一个删除按钮
<Custom:DataGrid Margin="0" ItemsSource="{Binding Todos}" AutoGenerateColumns="False">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
<Custom:DataGridTemplateColumn>
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button CommandParameter="{Binding}"
Command="{Binding ElementName=ConfirmDeleteDialog, Path=ShowCommand}"
Content="Delete" />
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
</Custom:DataGridTemplateColumn>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
<local:ConfirmationDialog x:Name="ConfirmDeleteDialog"
Title="Confirm delete!"
d:LayoutOverrides="Width"
Message="Are you sure that you want to delete the selected todo?"
YesCommand="{Binding DeleteCommand}" />
由于我在 DataTemplate 中找不到元素,我无法结合 ElementName 和相对源,所以我将如何定义可以访问在数据模板之外声明的元素的绑定?
我试图绑定的命令位于 ConfirmationDialog.YesCommand..
【问题讨论】:
标签: wpf data-binding