设置CornerRadius值我已经定义了一个静态资源:不能从静态资源
<UserControl x:Class="MyProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Width="255"
Height="300">
<UserControl.Resources>
<sys:Double x:Key="CornerRadiusValue">5</sys:Double>
</UserControl.Resources>
...
后来在XAML文件,我想对国境设置左上角半径时使用该值:
<Border
Width="40"
Height="30"
BorderThickness="1,1,0,0"
BorderBrush="Red">
<Border.CornerRadius>
<CornerRadius TopLeft="{StaticResource CornerRadiusValue}" />
</Border.CornerRadius>
</Border>
在设计时,一切正常,并且改变了值为CornerRadiusValue
静态资源更改了边框上的圆角半径。然而,当我要运行它,我得到一个XamlParseException
例外,与消息:
无法设置只读属性`System.Windows.CornerRadius.TopLeft”。
我在做什么错?我如何使它工作?谢谢。
请注意我确实需要详细说明左上角。其他角落应该绑定到其他一些静态资源值... – Boris 2012-02-01 13:02:29
如果您想在运行时更改它,请将其设为DynamicResource。 – 0x4f3759df 2012-02-01 16:01:08