How to style the select all button in datagrid?

这一生的挚爱 提交于 2020-06-28 17:46:41

问题


I have a xaml datagrid definition, I have all my styles set up and all, but I don't know how to style that top left button in the corner of the datagrid which works as "select all" when you press it.

For example, I can style datagrid cells like this:

<Style TargetType="DataGridCell">...

So how do I style that select all button? Is there something like?

<Style TargetType="DataGridSelectAllButton">

?


回答1:


Right, so if we go look at the docs and do a quick page search there for "the button in the upper left corner of the DataGrid" we'll find ResourceId=DataGridSelectAllButtonStyle about halfway through that page, and at the top of their template examples.

I would suggest using Blend to tear down the parts of controls like this, sometimes elements can be pretty buried and it's pretty darn handy to be able to just right-click and keep editing your way through the templates until you find what you need instead of trying to do it blind which sometimes can be a real pain. Plus, checking the docs first should be the intuitive first thought.

Anyway hope this helps, cheers.




回答2:


Add this to your resources:

<Style x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}" TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                ...
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


来源:https://stackoverflow.com/questions/23805715/how-to-style-the-select-all-button-in-datagrid

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