我尝试在 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/