ControlTemplate 中 Bingding 附加属性时需要加入 Path
Posted aguan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ControlTemplate 中 Bingding 附加属性时需要加入 Path相关的知识,希望对你有一定的参考价值。
<Style TargetType="{x:Type GroupBox}" BasedOn="{StaticResource MaterialDesignGroupBox}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Foreground" Value="{Binding (TextElement.Foreground), RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type FrameworkElement}}}"/> Property="materialDesignMahApps:ShadowAssist.ShadowDepth" Value="Depth0"/> <Setter Property="materialDesignMahApps:ColorZoneAssist.Mode" Value="PrimaryMid"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GroupBox}"> <DockPanel Background="{TemplateBinding Background}"> <materialDesignMahApps:ColorZone Background="{StaticResource PrimaryHueMidBrush}" x:Name="PART_ColorZone" DockPanel.Dock="Top" Mode="{Binding Path=(materialDesignMahApps:ColorZoneAssist.Mode), RelativeSource={RelativeSource TemplatedParent}}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" materialDesignMahApps:ShadowAssist.ShadowEdges="{Binding Path=(materialDesignMahApps:ShadowAssist.ShadowEdges), RelativeSource={RelativeSource TemplatedParent}}" UseLayoutRounding="True"> <ContentControl HorizontalAlignment="Left" Foreground="White" VerticalAlignment="Center" FontSize="20" FontWeight="DemiBold" Margin="10 0 0 4" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" Content="{TemplateBinding Header}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </materialDesignMahApps:ColorZone> <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </DockPanel> </ControlTemplate> </Setter.Value> </Setter> </Style>
以上是关于ControlTemplate 中 Bingding 附加属性时需要加入 Path的主要内容,如果未能解决你的问题,请参考以下文章
是否可以在ControlTemplate中包含Xaml资源?
WPF中ControlTemplate和DataTemplate的区别
在 ContentPresenter 中确保 AdornmentDecorator,但没有 ControlTemplate