设置嵌套在GridViewRowPresenter中的ContentPresenter的样式 [英] Styling the ContentPresenter nested inside GridViewRowPresenter

查看:355
本文介绍了设置嵌套在GridViewRowPresenter中的ContentPresenter的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在XamlPad中,可视树"屏幕显示以下内容:

In XamlPad, the Visual Tree display shows the following:

:ListViewItem

:GridViewRowPresenter

:ContentPresenter

我可以在Xaml中设置ListViewItems和GridViewRowPresenter的样式,但是如何控制像这些ContentPresenters的Margin属性一样简单的东西?请注意,设置内容演示者的样式很容易,但是我还没有学习如何设置由GridViewRowPresenter创建的ContentPresenters的样式.解决此问题的唯一方法是使用代码而不是Xaml吗?

谢谢.

推荐答案

您可以使用ItemContainerStyle属性来定义样式应用于ListViewItem,并且如果您想定义将用于内容的模板,则可以定义ItemTemplate.它将用作内容演示者的ContentTemplate属性.

You can use the ItemContainerStyle property to define a style that apply to your ListViewItem, and can define an ItemTemplate if you want to define what template will be used for your content. It will be used as the ContentTemplate property of the content presenter.

如果要更改内容演示者的样式,则必须通过调用VisualTreeHelper.GetParent()搜索元素来通过代码完成.

If you want to change the style of the content presenter, you'll have to do it through code by searching for the element by calling VisualTreeHelper.GetParent().


这篇关于设置嵌套在GridViewRowPresenter中的ContentPresenter的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆