【问题标题】:Xamarin Forms: custom progressbar renderer for UWP and win8.1Xamarin Forms:UWP 和 win8.1 的自定义进度条渲染器
【发布时间】:2017-05-31 15:07:36
【问题描述】:

您好,我正在使用 PCL 项目在 XAMARIN FORMS 中开发一个应用程序。我正在使用进度条。我需要更改填充区域的颜色。为此,我尝试了颜色属性,但它显示没有为进度条找到颜色属性。因此,为此我为进度条创建了一个自定义渲染器,以便我可以设置它的颜色,但我无法在 UWP 中找到任何属性来更改它的颜色。 谁能建议我一种方法来更改所有平台的填充区域颜色,特别是针对 UWP 和 windows 8.1。

For android and ios I have used this

【问题讨论】:

  • 没有代码示例?这个问题可能更具体....
  • @AnthonyLambert 我已经分享了 android 和 ios 的代码参考,我正在尝试为 uwp 和 win8.1 找出它

标签: c# xamarin uwp xamarin.forms


【解决方案1】:

更新:您是否尝试为 UWP 创建自定义渲染器并更改前景色?

var pb = Element as Windows.UI.Xaml.Controls.ProgressBar();
pb.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);

对于 UWP,您还可以覆盖 ProgressBar 的默认样式。 只需从here 获取默认样式并替换前景值,例如:

<Setter Property="Foreground" Value="Red" />

而不是将这种样式放在 UWP 特定项目中的 App.xaml 中

<Application
    x:Class="Xamarin.Prism.UWP.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    RequestedTheme="Light">

    <Application.Resources>

        <!-- Default style for Windows.UI.Xaml.Controls.ProgressBar -->
        PUT YOUR MODIFIED STYLE HERE

    </Application.Resources>

</Application>

现在所有 ProgressBar 控件都将使用您的自定义颜色

【讨论】:

  • 是否有任何类似 UWP 的方法可以使用,我可以从我的 xaml 页面中指定颜色代码,它将影响所有剩余的平台
  • 我刚开始使用 Xamarin 所以还不知道。
  • 如何通过字符串设置 SolidColorBrush
猜你喜欢
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
  • 2021-04-04
  • 2018-07-29
  • 2018-03-07
  • 2019-01-14
相关资源
最近更新 更多