【发布时间】:2014-05-30 20:39:51
【问题描述】:
我真的希望有人能在这里教我一些新东西,因为必须有一条更清洁的路线。
在工具包的Expander 控件的Style 模板内,有一个嵌入式ToggleButton,用于处理扩展器区域的切换。我想找到一种更好的方法来触摸特定的 UIElement,而不必重申 Expander 的整个样式。例如,如果它位于Expander 的Style 模板中;
<ToggleButton x:Name="ExpanderButton"
Grid.Row="0" Grid.Column="0"
MinWidth="0" MinHeight="0"
Margin="1"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontStretch="{TemplateBinding FontStretch}"
FontStyle="{TemplateBinding FontStyle}"
FontWeight="{TemplateBinding FontWeight}"
Foreground="{TemplateBinding Foreground}"
IsChecked="{TemplateBinding IsExpanded}"
Padding="{TemplateBinding Padding}"
Template="{StaticResource TheExpanderToggleButtonStyle}" />
我们看到Template="{StaticResource TheExpanderToggleButtonStyle}" 只是指向另一个单独的ControlTemplate 用于那个ToggleButton 对吗?所以我希望我可以在实例级别做一些事情,并且只为 ToggleButton 提供一个不同的模板,也许可以像这样实现它;
<toolkit:Expander>
<toolkit:Expander.Resources>
<Style TargetType="ToggleButton">
<Setter Property="Template" Value="{StaticResource ADifferentToggleButtonStyle}"/>
</Style>
</toolkit:Expander.Resources>
<TextBlock Text="Blah"/>
</toolkit:Expander>
...或者相同类型的概念多种不同的方式我可以从类似的例子中想到,我真的没想到会工作它只是碰巧是我在发布之前尝试的最后一个,试图把它扔在头上,我什至不知道有多少不同的尝试,但无济于事。所以我现在只是复制两个该死的模板来制作一个自定义扩展器,但就像我说的那样,我希望有人能教我一种更好的方法,这在未来会很有帮助。干杯!
【问题讨论】:
标签: silverlight xaml templates controltemplate