2016-04-27 50 views
1

我正在执行UWP应用程序。我的一个UserControl具有一个依赖项属性,它是一个SolidColorBrush获取UWP应用程序中画笔的可能值之一

在WPF中,我下面的:

public static readonly DependencyProperty BackgroundColorProperty = 
    DependencyProperty.Register("BackgroundColor", typeof(SolidColorBrush), typeof(StarControl), 
    new FrameworkPropertyMetadata((SolidColorBrush)Brushes.Transparent, 
      new PropertyChangedCallback(OnBackgroundColorChanged))); 

就目前而言,UWP,我下面的:

public static readonly DependencyProperty BackgroundColorProperty = 
      DependencyProperty.Register("BackgroundColor", typeof(SolidColorBrush), typeof(StarControl),new PropertyMetadata(/* ?????*/, OnBackgroundColorChanged)); 

的问题是,Brushes并不似乎是可用,应该使用什么?

谢谢

+0

您是通过XAML还是通过代码设置属性? –

+0

@TomDroste问题是关于如何在代码 – J4N

回答

2

没有Brushes相当于UWP。使用Colors类中的一个静态值创建SolidColorBrush。

DependencyProperty.Register(
    "BackgroundColor", typeof(SolidColorBrush), typeof(StarControl), 
    new PropertyMetadata(new SolidColorBrush(Colors.Transparent), OnBackgroundColorChanged)); 

除此之外,你的财产不应该叫BackgroundColor当它实际上是一个刷机,所以最好把它BackgroundBrush

+0

中设置DP的默认值('//?? * /'在我的代码中)。但是在WPF中,所有可能的颜色都有一个单独的'Brush' '刷子'静态类,出于性能原因(无需每次使用刷子时都实例化一个)。 UWP中没有这样的东西吗? – J4N

+0

在我的知识中,颜色方面是,但颜色。我不知道SolidColorBrush是否有相应的功能。你可以为它创建自己的单例。 –

相关问题