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

发布于 2025-01-03 06:32:33 字数 4867 浏览 1 评论 0原文

我正在将 WPF 工具包用于需要 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>

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

I'm using the WPF Toolkit for a project that I need an Accordion control. The control initially works fine (there is a known design bug but otherwise no problem), but anyone who tried the control knows that weird blue background that comes with it. I want to change the default background for the control and I go to Expression Blend, right click an AccordionItem instance, and go to Edit Template -> Edit a Copy. I select to apply it all app-wise, and it creates a new template (which should be identical to the original). The control looks exactly the same, but anything inside an AccordionItem gets invisible. No errors, no warnings. They just get invisible. When I click their tag in XAML, I can see they are selected, just as if they are behind something, but they aren't! When I delete the (never-touched) control template from the App.xaml, it gets back to normal, but I'm back again with the blue background. Here is the untouched XAML template created by Blend:

    <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>

Am I missing something? I am not super used to templates and styles, but anything from "Edit a copy", in an untouched state, should act identical to the default template, but it doesn't. I can safely delete the setters other than the Template, and it won't change. There is something with the Template setter, which makes the AccordionItem act abnormally.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百变从容 2025-01-10 06:32:33

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

You just delete string Background="Blue" this property is of the Grid which is first child of Control Template.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文