通过资源字典控制模板和主题相关的数据分离

发布于 2025-01-02 14:59:46 字数 1073 浏览 5 评论 0原文

我有几个带有主题相关数据的资源字典,我在其中声明了特定元素的样式:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山川志 2025-01-09 14:59:47

我不知道纯 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文