Silverlight DataGrid:整个行上的工具包上下文菜单
我正在开发一个 Silverlight 4 应用程序,并希望实现一个看似简单的任务: 我有这个 DataGrid:
<sdk:DataGrid x:Name="dg" Grid.Row="1" Grid.ColumnSpan="2" Width="800" ItemsSource="{Binding SearchResults}" AutoGenerateColumns="False" >
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn SortMemberPath="Name" Header="Name" CellTemplate="{StaticResource SearchGridNameFieldtemplate}">
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn SortMemberPath="samAccountName" Header="Kontoname" CellTemplate="{StaticResource SearchGridAccountNameFieldtemplate}">
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn Header="Description"
Binding="{Binding Principal.Description}" />
<sdk:DataGridTextColumn Header="Container"
Binding="{Binding Principal.ContainerDN}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
现在我正在为 TemplateColumn 使用 DataTemplate,它使用这样的工具包上下文菜单
<DataTemplate x:Key="DirectoryUserSearchItemViewModel" >
<StackPanel Orientation="Horizontal">
<controlsInputToolkit:ContextMenuService.ContextMenu>
<controlsInputToolkit:ContextMenu>
<controlsInputToolkit:MenuItem Header="Eigenschaften" Command="{Binding EditItem}" Visibility="{Binding User.DistinguishedName, Converter={StaticResource UserPermissionVisibilityConverter},ConverterParameter=1;8}" CommandParameter="{Binding User}">
<controlsInputToolkit:MenuItem.Icon>
<Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/>
</controlsInputToolkit:MenuItem.Icon>
</controlsInputToolkit:MenuItem>
<controlsInputToolkit:MenuItem Header="User endgültig löschen" Command="{Binding HardDeleteAccount}" Visibility="{Binding HardDeleteCommandVisibility}" CommandParameter="{Binding User}">
<controlsInputToolkit:MenuItem.Icon>
<Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/>
</controlsInputToolkit:MenuItem.Icon>
</controlsInputToolkit:MenuItem>
<controlsInputToolkit:MenuItem Header="Externe Anwendung ausführen" Command="{Binding ExecuteExternalApplication}" CommandParameter="{Binding User}">
<controlsInputToolkit:MenuItem.Icon>
<Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/>
</controlsInputToolkit:MenuItem.Icon>
</controlsInputToolkit:MenuItem>
</controlsInputToolkit:ContextMenu>
</controlsInputToolkit:ContextMenuService.ContextMenu>
<TextBlock Text="{Binding Principal.Name}"/>
</StackPanel>
</DataTemplate>
这是有趣的部分:如果我希望能够,我是否真的必须复制粘贴网格中每个列的整个上下文菜单数据模板右键单击连续任意位置并激活上下文菜单?我不能为整行设置这个吗? stackoverflow 上的其他帖子似乎没有给出这个具体问题的答案。
I'm developing a Silverlight 4 application and want to achieve a seemingly easy task:
I have this DataGrid:
<sdk:DataGrid x:Name="dg" Grid.Row="1" Grid.ColumnSpan="2" Width="800" ItemsSource="{Binding SearchResults}" AutoGenerateColumns="False" >
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn SortMemberPath="Name" Header="Name" CellTemplate="{StaticResource SearchGridNameFieldtemplate}">
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn SortMemberPath="samAccountName" Header="Kontoname" CellTemplate="{StaticResource SearchGridAccountNameFieldtemplate}">
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn Header="Description"
Binding="{Binding Principal.Description}" />
<sdk:DataGridTextColumn Header="Container"
Binding="{Binding Principal.ContainerDN}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
Now I am using a DataTemplate for the TemplateColumn which uses a toolkit Contextmenu like this
<DataTemplate x:Key="DirectoryUserSearchItemViewModel" >
<StackPanel Orientation="Horizontal">
<controlsInputToolkit:ContextMenuService.ContextMenu>
<controlsInputToolkit:ContextMenu>
<controlsInputToolkit:MenuItem Header="Eigenschaften" Command="{Binding EditItem}" Visibility="{Binding User.DistinguishedName, Converter={StaticResource UserPermissionVisibilityConverter},ConverterParameter=1;8}" CommandParameter="{Binding User}">
<controlsInputToolkit:MenuItem.Icon>
<Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/>
</controlsInputToolkit:MenuItem.Icon>
</controlsInputToolkit:MenuItem>
<controlsInputToolkit:MenuItem Header="User endgültig löschen" Command="{Binding HardDeleteAccount}" Visibility="{Binding HardDeleteCommandVisibility}" CommandParameter="{Binding User}">
<controlsInputToolkit:MenuItem.Icon>
<Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/>
</controlsInputToolkit:MenuItem.Icon>
</controlsInputToolkit:MenuItem>
<controlsInputToolkit:MenuItem Header="Externe Anwendung ausführen" Command="{Binding ExecuteExternalApplication}" CommandParameter="{Binding User}">
<controlsInputToolkit:MenuItem.Icon>
<Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/>
</controlsInputToolkit:MenuItem.Icon>
</controlsInputToolkit:MenuItem>
</controlsInputToolkit:ContextMenu>
</controlsInputToolkit:ContextMenuService.ContextMenu>
<TextBlock Text="{Binding Principal.Name}"/>
</StackPanel>
</DataTemplate>
Here's the fun part: Do I really have to copy paste the whole context menu datatemplate FOR EACH column in my grid if I want to be able to right click anywhere in a row and activate the context menu? Can't I set this for an entire row? Other posts on stackoverflow didnt seem to give an answer to this specific problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如帖子 https://stackoverflow.com/a/8795056/451495 中推荐的那样
您可以使用以下内容:
As recomended in post https://stackoverflow.com/a/8795056/451495
You can use following:
您可以尝试添加列名称,然后调用 ContextMenuService.SetContextMenu 将 ContextMenu 添加到其他列。
下一个挑战是确定右键单击了哪一列。
相关帖子:
如何获取 ContextMenu 的所有者(来自 Silverlight 4 工具包)?
Silverlight Toolkit ContextMenu:右键单击了哪个控件?< br>
You might try adding column names and then calling ContextMenuService.SetContextMenu to add the ContextMenu to the other columns.
The next challenge is determining which column was right-clicked.
Related posts:
How to get the Owner of the ContextMenu (from Silverlight 4 toolkit)?
Silverlight Toolkit ContextMenu: Which control was right-clicked?