CustomDataGrid命令中命令参数为空
这段代码工作正常:
<sdk:DataGrid ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem,Mode=TwoWay}" x:Name="dataGrid">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementName=MainTabControl,Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
在我的 CustomDataGrid 中,命令执行,但 CommandParameter 为 null :
<customControl:CustomDataGrid ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem,Mode=TwoWay}" x:Name="dataGrid">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementName=MainTabControl,Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
编辑: 我的 CustomDataGrid
由标准 DataGrid
驱动,并向其中添加一个事件。它覆盖
两个事件
:OnLoadingRow
和OnUnLoadingRow
。
请注意一个简单的CommandParameter
,例如一个简单的字符串,发送得很好。
而MainTabControl是:
<sdk:TabControl Name="MainTabControl"> ...
有什么问题吗?
This code works fine :
<sdk:DataGrid ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem,Mode=TwoWay}" x:Name="dataGrid">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementName=MainTabControl,Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
In my CustomDataGrid the Command executes but the CommandParameter is null :
<customControl:CustomDataGrid ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem,Mode=TwoWay}" x:Name="dataGrid">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementName=MainTabControl,Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
EDIT:
My CustomDataGrid
is driven from standard DataGrid
and add an Event to it. it override
s two event
: OnLoadingRow
and OnUnLoadingRow
.
Note that a simple CommandParameter
e.g. a simple string was sent fine.
And MainTabControl is:
<sdk:TabControl Name="MainTabControl"> ...
What is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我已经为您的情况构建了完整的模型,并提供了下面的所有代码。一切都是简单的,所以每个人都请减少我在其中放入的不良做法的数量:)
坏消息是,我的派生类与普通 DataGrid 的工作方式完全相同!当使用派生网格命中命令断点时,参数与 TabControl 类型完全相同。
为了更进一步,我需要看看你还可以做什么(除了你已经提到的)。如果您不想公开您的代码,请随时通过我的网站与我联系。
视图:
代码隐藏:
ViewModel:
自定义数据网格:
OK, I have built a complete mockup of your situation and provided all code below. Everything is bare-bones, so everyone please ease up on the number of bad practices I put in it :)
The bad new is, that my derived class works exactly the same as the normal DataGrid! When the command breakpoint is hit with the derived grid the parameter is exactly the same TabControl type.
To take this further I would need to see what else you may be doing (in addition what you have already mentioned). Feel free to contact me through my website if you do not want to make your code public.
View:
Code-behind:
ViewModel:
Custom datagrid: