【发布时间】:2019-02-13 10:19:50
【问题描述】:
我正在尝试为某个样式使用的资源中的 CornerRadius 设置一个值,但无法使其正常工作。这是我的代码的样子:
C#代码:
Current.Resources["FrameCornerRadius"] = "25";
followed by many other lines like this which all work okay
风格:
<Style x:Key="FrameBorder" TargetType="Frame">
<!-- Following line does not give any corner radius -->
<Setter Property="CornerRadius" Value="{DynamicResource FrameCornerRadius}" />
<!-- Following line gives corner radius -->
<!--<Setter Property="CornerRadius" Value="25" />-->
</Style>
Xaml
<Frame Style="{StaticResource FrameBorder}">
<StackLayout Orientation="Vertical" Spacing="0">
<xaml:ButtonXaml />
</StackLayout>
</Frame>
当我使用Value="{DynamicResource FrameCornerRadius}" 设置它时,它不起作用。当我直接将其设置为 25 时,它可以工作。请注意,我有 30 个或更多其他 Current.Resources 都运行良好,所以我认为这不是问题。
供参考:
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/Frame.cs
公共浮动 CornerRadius { 获取;放; }
【问题讨论】:
-
FrameCornerRadius不是静态资源而不是动态资源吗? -
我认为它的设置方式是可以的,例如另一个属性:
在样式中指定并且有效好的。只是不是 FrameCornerRadius -
尝试使用静态资源,看看是否可行,虽然我觉得应该可行,因为如果我没记错的话,这不是动态资源
-
当我使用 DynamicResource 这个词时,它不会出错,但不会产生角落。当我使用StaticResource这个词时,它给出了这个错误:StaticResource not found for key FrameCornerRadius 应用程序中所有其他类似的绑定都使用DynamicResource,所以我真的不确定此时有什么问题。
-
其他有效的可以给我看一个吗?
标签: xamarin xamarin.forms