如何仅在选择 Silverlight DataGrid 行时显示按钮

发布于 2024-10-18 00:21:45 字数 1620 浏览 4 评论 0原文

如何仅在选择 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末染殇 2024-10-25 00:21:45

每当您想要更改 Silverlight 中任何内容的视觉外观时,您都必须考虑 VisualStateManager。要更改所选 DataGrid 单元格的外观,您需要利用 VSM 的神奇功能。通过编辑 DataGridColumn.CellStyle 的“选定”状态,您可以更改选定网格单元格的外观。

  1. 在 Blend 中,将新的 DataGrid 拖放到页面上。
  2. 右键单击 DataGrid 并选择“添加列 --> 添加 DataGridTemplateColumn”
  3. 右键单击​​“对象和时间轴”窗格中的 DataGridTemplateColumn,然后转到“编辑列样式 --> 编辑单元格样式 --> 编辑副本
  4. ”单击“对象和时间线”窗格中的“样式”,然后转到“编辑模板 --> 编辑当前”。
  5. 现在有趣的部分来了,如何具体解决按钮消失的问题。如果按钮是 CellTemplate 中唯一的东西,那么您可以隐藏单元格的全部内容。
  6. 从“状态”窗格中选择“选定”状态。
  7. 将 CellStyle.Template 中 ContentPresenter 的可见性设置为 Collapsed。 (更好的用户体验是添加一个 0.3 秒的动画,将不透明度从 100% 变为 0%)。

本质上,整个教程是关于获取 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.

  1. In Blend, drag and drop a new DataGrid on a Page.
  2. Right click on the DataGrid and choose "Add Column --> Add DataGridTemplateColumn"
  3. Right click on the DataGridTemplateColumn in the "Object and timeline" pane and go "Edit Column Styles --> Edit CellStyle --> Edit Copy"
  4. Right click on "Style" in the "objects and timeline" pane and go "Edit Template --> Edit Current".
  5. Now comes the interesting part, how to specifically solve the problem of a disappearing button. If the button is the only thing you've got in that CellTemplate then you can just hide the whole contents of the cell.
  6. Select the "Selected" state from the "States" pane.
  7. Set the visibility of the ContentPresenter in the CellStyle.Template to Collapsed. (A nicer UX would be to add a 0.3seconds animation taking opacity from 100% to 0%).

Essentially this whole tutorial is about getting to the CellStyle.Template for your DataGridColumn and adding an animation to the Selected State.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文