【问题标题】:How to style ItemsPresenter in WPF?如何在 WPF 中设置 ItemsPresenter 的样式?
【发布时间】:2017-11-29 03:37:59
【问题描述】:

我有一个包含时间线视图的项目 (this one)。我需要这个时间线视图的背景是透明的(因为我正在渲染它后面的其他对象/控件)。有一个元素是不透明的,所以我需要将其更改为透明。

如果我在调试执行期间检查视图中的元素,我可以看到需要更改的元素是 ItemsPresenter(见下图)。 ItemsPresenter 包含一个 StackPanel,当通过在实时可视树中编辑其属性来更改此堆栈面板的颜色时,问题已解决。

...如何为 ItemsPresenter 控件添加一种样式,该样式可以全局使用,也可以专门由时间线使用,从而更改它包含的堆栈面板的背景?能举个例子吗?

非常感谢您的帮助。

【问题讨论】:

    标签: c# wpf xaml itemscontrol itemspresenter


    【解决方案1】:

    ItemsControl 有一个ItemsPanelTemplate,您可以设置Background 的属性:

    <ItemsControl ...>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Background="Gray"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        ...
    </ItemsControl>
    

    【讨论】:

    • 谢谢mm8,正是我想要的。
    猜你喜欢
    • 2019-03-01
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    • 2013-11-26
    • 2014-11-11
    • 1970-01-01
    • 2019-07-22
    • 1970-01-01
    相关资源
    最近更新 更多