无法从WPF Toolkit为Accordion创建AccordionItem模板

时间:2012-02-07 15:25:13

标签: wpf xaml .net-4.0 wpftoolkit app.xaml

我正在使用WPF Toolkit进行我需要Accordion控件的项目。该控件最初工作正常(有一个已知的设计错误,但没有问题),但任何尝试控制的人都知道它附带的奇怪的蓝色背景。我想更改控件的默认背景,然后转到Expression Blend,右键单击AccordionItem实例,然后转到编辑模板 - >编辑副本。我选择以应用程序方式应用它,并创建一个新模板(应该与原始模板相同)。该控件看起来完全相同,但AccordionItem内的任何内容都不可见。没有错误,没有警告。他们只是看不见。当我在XAML中单击它们的标签时,我可以看到它们被选中,就好像它们落后于某些东西,但它们不是!当我从App.xaml中删除(从未触摸过的)控件模板时,它恢复正常,但我又回到了蓝色背景。以下是Blend创建的未触摸的XAML模板:

    <Style TargetType="{x:Type System_Windows_Controls:AccordionItem}">
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="#FFECECEC"/>
        <Setter Property="Background" Value="White"/>
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type System_Windows_Controls:AccordionItem}">
                    <Grid Background="Blue" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Border x:Name="Background" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1" Padding="{TemplateBinding Padding}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="cd0" Width="Auto"/>
                                    <ColumnDefinition x:Name="cd1" Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition x:Name="rd0" Height="Auto"/>
                                    <RowDefinition x:Name="rd1" Height="Auto"/>
                                </Grid.RowDefinitions>
                                <System_Windows_Controls_Primitives:AccordionButton x:Name="ExpanderButton" Background="{TemplateBinding Background}" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="True" IsChecked="{TemplateBinding IsSelected}" Margin="0" Padding="0" Grid.Row="0" Style="{TemplateBinding AccordionButtonStyle}" VerticalAlignment="{TemplateBinding VerticalAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                <System_Windows_Controls_Primitives:ExpandableContentControl x:Name="ExpandSite" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="False" Margin="0" Percentage="0" RevealMode="{TemplateBinding ExpandDirection}" Grid.Row="1" Style="{TemplateBinding ExpandableContentControlStyle}" VerticalAlignment="{TemplateBinding VerticalAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <System_Windows_Controls_Primitives:ExpandableContentControl.Clip>
                                        <RectangleGeometry/>
                                    </System_Windows_Controls_Primitives:ExpandableContentControl.Clip>
                                </System_Windows_Controls_Primitives:ExpandableContentControl>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

我错过了什么吗?我不是非常习惯于模板和样式,但是在“未编辑”状态下,“编辑副本”中的任何内容都应该与默认模板相同,但事实并非如此。我可以安全地删除模板以外的setter,它不会改变。模板设置器有一些东西,它使AccordionItem行为异常。

1 个答案:

答案 0 :(得分:2)

您只需删除字符串Background="Blue",此属性属于Grid Control Template的第一个孩子。