Silverlight ControlTemplate 中的静态资源?

发布于 2024-08-02 02:39:00 字数 680 浏览 1 评论 0原文

我尝试在 ControlTemplate 中使用 StaticResource 作为自定义对象,并且每当呈现该对象时,应用程序都会崩溃。 正如您在下面的代码中看到的,我在 App.XAML 中定义了模板和资源。 我一直在进行一些搜索,看看是否/为什么不允许这样做,但到目前为止还没有运气。

    <Color x:Key="PersonBackground">#FF003B00</Color>

    <ControlTemplate x:Key="PersonTemplate" TargetType="this:Person">
        <Border Background="{StaticResource PersonBackground}" BorderBrush="White" 
                BorderThickness="2" CornerRadius="10" MinHeight="70" MinWidth="120">
    ...
    </ControlTemplate>

如果有人能解释为什么这是不允许的或者我做错了什么(或者,最好的是,在 Silverlight 中进行自定义主题的更好方法),我将不胜感激。

编辑:我觉得我应该指定我主要只是对能够在一个地方设置配色方案感兴趣; 主题的其余部分不需要做太多改变。

I'm trying to use a StaticResource in a ControlTemplate for a custom object, and whenever that object is rendered, the application crashes. As you can see in the code below, I define both the template and the resource in App.XAML. I've been doing a bit of searching to see if/why this isn't allowed, but have had no luck so far.

    <Color x:Key="PersonBackground">#FF003B00</Color>

    <ControlTemplate x:Key="PersonTemplate" TargetType="this:Person">
        <Border Background="{StaticResource PersonBackground}" BorderBrush="White" 
                BorderThickness="2" CornerRadius="10" MinHeight="70" MinWidth="120">
    ...
    </ControlTemplate>

If anyone could explain why this isn't allowed or what I'm doing wrong (or, best yet, a better way to do custom theming in Silverlight), I would greatly appreciate it.

Edit: I feel like I should specify that I'm mostly just interested in being able to set the color scheme in one place; the rest of the theme won't need to change as much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

单调的奢华 2024-08-09 02:39:00

而不是颜色吗?

您可以尝试使用 SolidColorBrush

Instead of Color, can you try using a SolidColorBrush

<SolidColorBrush x:Key="PersonBackground" Color="#FF003B00"/>

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