Silverlight ControlTemplate 中的静态资源?
我尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是颜色吗?
您可以尝试使用 SolidColorBrush
Instead of Color, can you try using a SolidColorBrush
<SolidColorBrush x:Key="PersonBackground" Color="#FF003B00"/>