如何仅在选择 Silverlight DataGrid 行时显示按钮
如何仅在选择 DataGridTemplateColumn 的行时才显示该按钮?我已经尝试过了,但是当然没有可用的 IsSelected
。在行绑定到的实体上拥有 IsSelected
属性是没有意义的,即使如此,我也不想将我的 DataGrid
耦合到我的模型那么紧。无论如何,接口可以自己处理这个问题吗?
这就是我所拥有的:
<sdk:DataGrid Name="_categorySummaryDataGrid"
MinHeight="200"
ItemsSource="{Binding ElementName=_userControl, Path=CategorySummaries}"
AutoGenerateColumns="False" RowDetailsVisibilityMode="VisibleWhenSelected">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="_nameColumn" Binding="{Binding Path=Name}" Header="Name" Width="Auto" IsReadOnly="True" />
<sdk:DataGridTextColumn x:Name="_descriptionColumn" Binding="{Binding Path=Description}" Header="Description" Width="*" IsReadOnly="True" />
<sdk:DataGridTemplateColumn x:Name="_detailsColumn" Width="Auto">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="..." ToolTipService.ToolTip="View Category Details"
Visibility="{Binding Path=IsSelected, Converter={StaticResource BooleanToVisibility}}"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
出于设计原因,我希望该按钮仅在选择包含该按钮的行时才显示。而且,如果可能的话,我希望当该行悬停时它以不同的方式显示。
Silverlight 和 WPF 似乎有更多我所希望的限制。我希望这些事情都是可能的。谢谢。 :)
编辑:
我没有,也不会获得 Expression Blend。谢谢,仅此而已。
How can I display a button in a DataGridTemplateColumn
only when its row is selected? I've tried this, but of course there is no IsSelected
available to me. It doesn't make sense to have an IsSelected
property on the entity to which the rows are bound, and even so I wouldn't want to have to couple my DataGrid
to my model that tightly. Is there anyway that the interface can handle this itself?
This is what I have:
<sdk:DataGrid Name="_categorySummaryDataGrid"
MinHeight="200"
ItemsSource="{Binding ElementName=_userControl, Path=CategorySummaries}"
AutoGenerateColumns="False" RowDetailsVisibilityMode="VisibleWhenSelected">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="_nameColumn" Binding="{Binding Path=Name}" Header="Name" Width="Auto" IsReadOnly="True" />
<sdk:DataGridTextColumn x:Name="_descriptionColumn" Binding="{Binding Path=Description}" Header="Description" Width="*" IsReadOnly="True" />
<sdk:DataGridTemplateColumn x:Name="_detailsColumn" Width="Auto">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="..." ToolTipService.ToolTip="View Category Details"
Visibility="{Binding Path=IsSelected, Converter={StaticResource BooleanToVisibility}}"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
For design reasons, I want the button to only show when the row that contains it is selected. And, if possible, I want it to show in a different way when the row is being hovered over.
There seem to be more limitations to Silverlight and WPF that I had hoped. I hope that these things are possible. Thanks. :)
Edit:
I do not have, and will not be getting Expression Blend. Thank you, that is all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当您想要更改 Silverlight 中任何内容的视觉外观时,您都必须考虑 VisualStateManager。要更改所选 DataGrid 单元格的外观,您需要利用 VSM 的神奇功能。通过编辑 DataGridColumn.CellStyle 的“选定”状态,您可以更改选定网格单元格的外观。
本质上,整个教程是关于获取 DataGridColumn 的 CellStyle.Template 并向选定状态添加动画。
Whenever you want to change the visual appearance of anything in Silverlight, you have to think in terms of VisualStateManager. To change the appearance of a Selected DataGrid cell, you'll need to avail yourself to the wonders of VSM. By editing DataGridColumn.CellStyle's "Selected" state you can change the appearance of the selected grid cell.
Essentially this whole tutorial is about getting to the CellStyle.Template for your DataGridColumn and adding an animation to the Selected State.