无法从 WPF Toolkit 为 Accordion 创建 AccordionItem 模板
我正在将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需删除字符串
Background="Blue"
,该属性属于Grid
,它是Control Template
的第一个子级。You just delete string
Background="Blue"
this property is of theGrid
which is first child ofControl Template
.