从 DataGridCell 获取控件
假设我在 DataGridTemplateColumn 中有一个任意控件,我希望知道如何获取该控件,因为我已经检索了包含该控件的 DataGridCell。
包含 DataGrid 的 XAML 文件如下:
<DataGrid Name="dgMovement">
...
<DataGridTemplateColumn Header="Target %">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<vi:PercentageEditor Value="{Binding TargetPercentage, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" Width="100px"
cal:Message.Attach="[Event PreviewLostKeyboardFocus] = [Action ChangeTargetPercentage];[Event PreviewGotKeyboardFocus] = [Action OnFocus]"
Name="aa" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>...
我使用扩展方法检索了 DataGridCell,如下所示:
DataGridCell cell = view.dgMovement2.GetCell(index, 6);
找到包含在静态类中的扩展方法 此处
问题是,一旦获得 DataGridCell,如何检索“PercentageEditor”?有人可以帮助我吗?任何帮助将不胜感激。谢谢!
Assuming that I have an arbitrary control inside a DataGridTemplateColumn, I wish to know how to get the control, given that I have retrieved the DataGridCell which contains that control.
My XAML file containing the DataGrid is as follows:
<DataGrid Name="dgMovement">
...
<DataGridTemplateColumn Header="Target %">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<vi:PercentageEditor Value="{Binding TargetPercentage, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" Width="100px"
cal:Message.Attach="[Event PreviewLostKeyboardFocus] = [Action ChangeTargetPercentage];[Event PreviewGotKeyboardFocus] = [Action OnFocus]"
Name="aa" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>...
I retrieved the DataGridCell using extension methods as follows:
DataGridCell cell = view.dgMovement2.GetCell(index, 6);
The extension methods, contained in a static class is found here
The question is, how to I retrieve the "PercentageEditor", once I got the DataGridCell? Can anybody help me? Any help would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用控件的名称在模板中找到它,例如
请注意,这通常不是必需的,因为修改模板化控件大部分可以使用数据绑定、附加属性和单独的事件。一般来说,我会通过代码将模板访问限制为自定义控件(通常具有 指定部分)。
You can use the name of the control to find it in the template, e.g.
Note however that this usually should not be necessary as modifying templated controls for the most part can be done using data binding, attached properties and events alone. In general i would restrict template access via code to custom controls (which often have designated parts).
这对我有用(C#)
This worked for me (C#)