DataGridTextColumn event binding

余生长醉 提交于 2019-12-24 09:25:52

问题


What is the simplest way to bind an ICommand to a DataGridTextColumn that will handle a user double click on that column without code behind? Can I somehow expose an underlying FE and do it all in the XAML?

This particular column is read only and here is the xaml for it:

<dg:DataGridTextColumn Header="Number" Binding="{Binding BusinessId}" 
                                   Width="75" IsReadOnly="True" CanUserReorder="False" 
                                   />

Cheers,
Berryl


回答1:


the short answer is no.

you cant create a new command property on a column in xaml. In the past when dealing with this problem I:

  • derive from the column and add the command

  • derive from the grid and override the preview onmousedoubleclick method

or

  • put an event handler in the code behind of the form hosting the grid

then

  • calculate which cell was double clicked on

  • get its parent column.

  • if it was a column of the derived type with the extra command property, fire the command on the column, or have the command on the derived grid and send the column as the command parameter.



来源:https://stackoverflow.com/questions/2352799/datagridtextcolumn-event-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!