通过资源字典控制模板和主题相关的数据分离
我有几个带有主题相关数据的资源字典,我在其中声明了特定元素的样式:
<Style TargetType="sdk:DataForm">
<Setter Property="Background" Value="{StaticResource Bckgrnd}"/>
</Style>
而且我还有 Generic.xaml,我想在其中设置此目标类型的模板,但我遇到了一种情况一个模板我必须使用多种颜色,但目标类型只有一种颜色属性。像这样的事情:
<Style TargetType="sdk:DataForm">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="sdk:DataForm">
<Grid ctl:DataField.IsFieldGroup="True">
....
<StackPanel Background="{TemplateBinding Background}" ...>
...
...
<!-- and I need another background from themes here -->
<StackPanel Background="{???}" ...>
...
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
问题是:在这种情况下,如果没有目标类型扩展之类的东西,如何使用不同的颜色?如果您能找到纯 xaml 解决方案,那就太好了。
谢谢
I have several resource dictionaries with theme-related data, where I declared styles for particular element this way:
<Style TargetType="sdk:DataForm">
<Setter Property="Background" Value="{StaticResource Bckgrnd}"/>
</Style>
And also I have Generic.xaml, where I want to set the template for this target type, but I was faced with a situation where in one template I have to use several colors but target type have only one property for color. Something like this:
<Style TargetType="sdk:DataForm">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="sdk:DataForm">
<Grid ctl:DataField.IsFieldGroup="True">
....
<StackPanel Background="{TemplateBinding Background}" ...>
...
...
<!-- and I need another background from themes here -->
<StackPanel Background="{???}" ...>
...
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And the question is: how can I use different colors in this case without something like target type extension? It will be great if you'll find pure xaml solution.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道纯 XAML 解决方案。我想我会创建 DataForm 的子类并向其添加 Brush 类型的依赖属性。然后在 XAML 中使用该类而不是 DataForm,并使用引用新属性的 TemplateBindings。
或者,如果您不想子类化 DataForm,也许您可以创建 Brush 类型的附加属性。
I don't know of a pure XAML solution. I think I would create a subclass of DataForm and add dependency properties of type Brush to it. Then use that class in the XAML instead of DataForm, and use TemplateBindings that reference the new properties.
Or, if you don't want to subclass DataForm, perhaps you could create attached properties of type Brush.