Implementing the double-click event on Silverlight 4 Datagrid

余生长醉 提交于 2019-12-22 08:46:58

问题


Any good soul have an example of implementing the "Command Pattern" introduced by Prism on a double click event in a Silverlight 4.0 DataGrid?

I tried the following:

<data:DataGrid x:Name="dgUserRoles" AutoGenerateColumns="False" Margin="0" Grid.Row="0" ItemsSource="{Binding Path=SelectedUser.UserRoles}" IsReadOnly="False">
    <data:DataGrid.Columns>
        <data:DataGridTemplateColumn Header="">
            <data:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Button Width="20" Height="20" Click="Button_Click" Command="{Binding EditRoleClickedCommand}" CommandParameter="{Binding SelectedRole}" />
                </DataTemplate>
            </data:DataGridTemplateColumn.CellTemplate>
        </data:DataGridTemplateColumn>
        <data:DataGridTextColumn Header="Role Name" Binding="{Binding RoleName}" />
        <data:DataGridTextColumn Header="Role Code" Binding="{Binding UserroleCode}" IsReadOnly="True"/>
        <data:DataGridCheckBoxColumn Header="UDFM Managed" Binding="{Binding RoleIsManaged}" IsReadOnly="True" />
        <data:DataGridCheckBoxColumn Header="UDFM Role Assigned" Binding="{Binding UserroleIsUdfmRoleAssignment}" IsReadOnly="True" />
        <data:DataGridTextColumn Header="Source User" Binding="{Binding SourceUser}" IsReadOnly="True" />
    </data:DataGrid.Columns>
</data:DataGrid>

As you see I did try to hook up the Command there and it is not firing the event in my View Model.

Looking for a good alternative.


回答1:


First, Button.Command is not for double-click. It will work with single click as well.

You need to change like that. ElementName=dgUserRoles, Path=DataContext.

 Command="{Binding ElementName=dgUserRoles, Path=DataContext.EditRoleClickedCommand}"


来源:https://stackoverflow.com/questions/2436945/implementing-the-double-click-event-on-silverlight-4-datagrid

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