类型Universe无法解析程序集:System.Xaml

时间:2016-08-08 17:00:11

标签: c# xamarin.forms uwp-xaml

我正在尝试为ProgressBar创建自定义渲染器,以便我可以更改其颜色。我的课程如下:

public class ColorProgressBar : ProgressBar
{
    public static BindableProperty BarColorProperty = BindableProperty.Create( "BarColor", typeof( Color ), typeof( ProgressBar ), Constants.ORANGE   );

    public Color BarColor
    {
        get { return (Color)GetValue( BarColorProperty ); }
        set { SetValue( BarColorProperty, value ); }
    }
}

然后,在MyApp.UWP项目中,我有:

[assembly: ExportRenderer (typeof(ColorProgressBar), typeof(ProgressBarRenderer))]
namespace MyApp.UWP
{
    public class ColorProgressBarRenderer : ProgressBarRenderer
    {
        public ColorProgressBarRenderer() {}

        protected override void OnElementChanged( ElementChangedEventArgs<ProgressBar> e )
        {
            base.OnElementChanged( e );

            if ( e.NewElement == null )
                return;

            if ( Control != null )
                UpdateBarColor();
        }

    protected override void OnElementPropertyChanged( object sender, PropertyChangedEventArgs e )
    {
        base.OnElementPropertyChanged( sender, e );

        if ( e.PropertyName == ColorProgressBar.BarColorProperty.PropertyName )
        {
            UpdateBarColor();
        }
    }

    private void UpdateBarColor()
    {
        var element = Element as ColorProgressBar;
        var color = Windows.UI.ColorHelper.FromArgb( (byte)255, (byte)247, (byte)137, (byte)30 );
        var brush = new Windows.UI.Xaml.Media.SolidColorBrush( color );
        Control.Foreground = brush;
    }
}
}

但是,我在构建时会在主题行中收到错误以及Cannot resolve Assembly or Windows Metadata file 'System.Xaml.dll'。我怀疑它与设置颜色和画笔有关,但我不确定如何获得正确的类别。

我只是想改变颜色:/

编辑:我添加了System.Xaml.dll程序集,现在我在构建时遇到App.xaml错误:Object reference is not set to an instance of an object。 Xamarin和System.Xaml.dll之间是否存在冲突?

0 个答案:

没有答案