【发布时间】:2020-07-22 10:07:30
【问题描述】:
我在 UWP 项目中使用 Syncfusion 的数据网格。除了GridTemplateColumn 内的按钮的命令绑定外,一切正常。可能是什么问题?
XAML
<my:GridTemplateColumn MappingName="Actions" HeaderText="Actions"
AllowFiltering="False">
<my:GridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Spacing="0" HorizontalAlignment="Center">
<Button VerticalAlignment="Center" Width="40" Content="Delete"
my:FocusManagerHelper.FocusedElement="True"
Command="{x:Bind ViewModel.RemoveBtnCommand}"/>
</StackPanel>
</DataTemplate>
</my:GridTemplateColumn.CellTemplate>
</my:GridTemplateColumn>
查看模型
public ICommand RemoveBtnCommand { get; }
public HRMDepartmentsViewModel()
{
IsActive = true;
RemoveBtnCommand = new AsyncRelayCommand(CommandRemoveBtnClickedExecute);
}
private async Task CommandRemoveBtnClickedExecute()
{
// never executed-- code here
}
我还尝试了什么
如果x:Bind,我尝试使用Binding,但它也不起作用
Command="{Binding Path=RemoveBtnCommand}" CommandParameter="{Binding}"
观察
如果我不使用Command 并使用Click 事件绑定,它就可以工作。
<my:GridTemplateColumn MappingName="Actions" HeaderText="Actions"
AllowFiltering="False">
<my:GridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Spacing="0" HorizontalAlignment="Center">
<Button VerticalAlignment="Center" Width="40" Content="Delete"
Click="{x:Bind ViewModel.ButtonBase_OnClick}"/>
</StackPanel>
</DataTemplate>
</my:GridTemplateColumn.CellTemplate>
</my:GridTemplateColumn>
查看模型
public void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
// It gets called
}
【问题讨论】:
标签: c# xaml uwp syncfusion