2

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

1 回答 1

2

看看有同样问题的人的这个MSDN 论坛线程。另请注意,此控件具有预览质量,根据 CodePlex,它等同于 Alpha 版本。

从上面的链接:

关键部分是绑定到实际的外部网格。出于某种原因,手风琴项目没有为内部网格提供一个宽度/高度来拉伸,所以你必须将它绑定到“更高”的东西上。


我对其进行了测试,它确实有效,但它确实给了设计者错误,Object reference not set to an instance of an object但它确实可以编译和运行。

<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>
于 2012-05-17T00:34:14.130 回答