C# UWP按钮栏MvvmLight/Telerik/WindowsTemplate Studio
我正在尝试将ButtonColumn添加到由Windows Template Studio生成的TelerikDataGrid中,而无需代码隐藏。 我认为,在一个完美的世界里,它会像这样工作C# UWP按钮栏MvvmLight/Telerik/WindowsTemplate Studio,c#,telerik,uwp-xaml,windows-template-studio,C#,Telerik,Uwp Xaml,Windows Template Studio,我正在尝试将ButtonColumn添加到由Windows Template Studio生成的TelerikDataGrid中,而无需代码隐藏。 我认为,在一个完美的世界里,它会像这样工作 <tg:DataGridTemplateColumn x:Uid="Table_Open" > <tg:DataGridTemplateColumn.CellContentTemplate > <DataTemplate>
<tg:DataGridTemplateColumn x:Uid="Table_Open" >
<tg:DataGridTemplateColumn.CellContentTemplate >
<DataTemplate>
<Button x:Uid="Button_Open" Command="{x:Bind ViewModel.OpenCustomerCommand}"></Button>
</DataTemplate>
</tg:DataGridTemplateColumn.CellContentTemplate>
</tg:DataGridTemplateColumn>
但是我没有在我的UWP案例中复制它。我恐怕你不能在
DataTemplate
中使用x:bind绑定OpenCustomerCommand
,如果我们想绑定viewmodel的OpenCustomerCommand
我们需要将当前页面DataContext
设置为viewmodel
,然后使用绑定标记扩展进行绑定,如下所示
<Button HorizontalAlignment="Right"
Margin="0,0,30,0"
Content="Favorite"
Command="{Binding ElementName=RootGrid,Path=DataContext.OpenCustomerCommand }"
/>
这是您可以参考的案例。对不起,我无法运行它。我将当前页面DataContext定义为ViewModel,如下所示:请给根面板一个x:name和binding ElementName=“panel name”。我这样做了,给了页面、网格、DataGrid一个自己的x:name,并尝试了所有这些。如果我在Path=DataContext.OpenCustomerCommand上点击F12,我在CustomerListViewModel中找到了该命令,但在Debug中仍然没有该命令的功能,那么也不会到达断点:(@Keke,可能是您需要将命令插入数据源。请参考此案例。我真的不知道如何解决。但是,我已经用ListView运行了它,并从stackoverflow上的其他问题中得到了答案。谢谢您的帮助,但无法将其标记为已解决,我想一定有办法用DataGrid运行它。
<Button HorizontalAlignment="Right"
Margin="0,0,30,0"
Content="Favorite"
Command="{Binding ElementName=RootGrid,Path=DataContext.OpenCustomerCommand }"
/>