wpf - 无法更改 XAML Accordion 中的蓝色背景

标签 wpf xaml background accordion

我尝试在 XAML 中使用折叠控件,但无法更改默认使用的深蓝色背景。我设法偶然发现其他一些人也遇到同样的问题,但没有发布解决方案。到目前为止,我找到的唯一答案涉及使用 Expression Studio,但不幸的是我没有副本。

请参阅下面的设计器代码,目前还没有太多内容,我尝试在每个元素上设置背景属性,但没有得到任何结果。

<Window x:Class="Test.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="289" 
    Width="500" 
    xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit">
    <Grid>
        <my:Accordion HorizontalAlignment="Stretch"  VerticalAlignment="Stretch">
            <my:AccordionItem x:Name="item1" Header="Item 1">
                <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                </Grid>
            </my:AccordionItem>
            <my:AccordionItem x:Name="item2" Header="Item 2">

            </my:AccordionItem>
            <my:AccordionItem x:Name="item3" Header="Item 3">

            </my:AccordionItem>
        </my:Accordion>        
    </Grid>
</Window>

最佳答案

看看这个 MSDN Forum thread有同样问题的人。另请注意,此控件的值为 Preview根据 CodePlex 的说法,其质量相当于 Alpha 版本。

来自上面的链接:

The key part is binding to the actual outer grid. For some reason, the accordion item isn't providing a width/height for the inner grid to stretch to, so you have to bind it to something "higher up" so to speak.


我测试了它,它确实有效,它确实给了设计者错误对象引用未设置到对象的实例但它确实编译并运行。

<Grid>
    <my:Accordion HorizontalAlignment="Stretch"  VerticalAlignment="Stretch">
        <my:AccordionItem x:Name="item1" Header="Item 1">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White" 
                Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}"
                Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}}, Path=ActualHeight}">
            </Grid>
        </my:AccordionItem>
        <my:AccordionItem x:Name="item2" Header="Item 2">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White"  
                Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}"
                Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}}, Path=ActualHeight}">
            </Grid>
        </my:AccordionItem>
        <my:AccordionItem x:Name="item3" Header="Item 3">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White" 
                Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}"
                Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}}, Path=ActualHeight}">
            </Grid>
        </my:AccordionItem>
    </my:Accordion>
</Grid>

关于wpf - 无法更改 XAML Accordion 中的蓝色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10625728/

相关文章:

wpf - 是否有在 XAML 中应用 Binding.ValidationRules 的简洁方法

.net - 通过拖放 (WPF) 显示提示文本

html - 为什么我的 UL 子菜单采用其祖 parent 的背景?

android - 更改带边框的按钮背景

javascript - Chrome 失败的图像背景卡住问题

c# - MVVM-有没有一种方法可以在不使用数据绑定(bind)的情况下获取和设置文本框的文本?

c# - 如何在服务器 app.config 中保存动态端点?

wpf - 如何将子文件夹中定义的 ResourceDictionary 添加到 App.xaml?

c# - 获得焦点并选择文本时文本左对齐

wpf - 为什么x :key required on ControlTemplate in the ResourceDictionary