ege*_*vin 5 wpf xaml styles controltemplate
我想访问嵌套在样式的控件模板内的属性。我知道您可以在后面的代码中执行此操作:
GradientStop stop = (GradientStop)progressBar1.Template.FindName("gradStop", progressBar1);
stop.Color = Colors.Black;
Run Code Online (Sandbox Code Playgroud)
是否可以这样做,但是在XAML中呢?例如:
<ProgressBar Style="{StaticResource CustomProgressBar}" [???].Color="FF000000"/>
Run Code Online (Sandbox Code Playgroud)
小智 2
不能使用TemplateBinding吗?
<Style x:Key="MyStyle" TargetType="{x:Type ContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<Border Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="{TemplateBinding Background}" >
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
然后在应用样式时指定模板绑定值。