【问题标题】:Does setting a float value in a style require some special code?在样式中设置浮点值是否需要一些特殊代码?
【发布时间】: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


【解决方案1】:

错误在于定义资源应该是这样的:

Current.Resources["FrameCornerRadius"] = 25;

祝你好运

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 2016-02-25
    • 2015-04-26
    • 2020-12-07
    • 2010-12-08
    • 1970-01-01
    • 2021-08-24
    相关资源
    最近更新 更多