首页 文章

为什么从UWP App的共享代码中删除了Dependencies部分?

提问于
浏览
1

我使用Visual Studio 2017的build 15.6.2构建了一个测试UWP应用程序.UWP项目是通过选择:“跨平台” - >“移动应用程序(Xamarin Forms)”,然后我选择:“空白应用程序”构建的 .

解决方案窗口如下所示:

enter image description here

请注意共享代码部分中的 Dependencies 部分 .

然后我用Visual Studio,build 15.6.4创建了一个类似的项目,我得到了一个解决方案窗口,如:

enter image description here

请注意, Dependencies 部分已被删除 . 我测试SkiaSharp的代码被破坏了,因为MainPage.xaml找不到SkiaSharp:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:skia="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
             x:Class="TrinMeter.MainPage">

  <skia:SKCanvasView x:Name="CanvasView"
                     PaintSurface="OnCanvasViewPaintSurface" />

</ContentPage>

为什么Microsoft删除了Dependencies部分?

查尔斯

2 回答

  • 0

    实际上项目是不同的 . 最上面的一个使用PCL或标准库来共享代码 . 底部使用共享库 . 要添加引用或nuget包,您需要将其添加到UWP,iOS和UWP应用程序 .

  • 0

    在尝试了几个模板后,我终于找到了正确的模板 .

    步骤1:

    enter image description here

    第2步:这非常重要 . 请注意,单选按钮已更改为“.NET Standard” .

    enter image description here

    第3步:现在我们可以添加依赖项,添加SkiaSharp

    enter image description here

    enter image description here

    MainPage.xml应如下所示:

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:skia="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
                 xmlns:local="clr-namespace:Test2"
                 x:Class="Test2.MainPage">
    
      <skia:SKCanvasView x:Name="CanvasView"
                         PaintSurface="OnCanvasViewPaintSurface" />
    
    </ContentPage>
    

    而代码隐藏是:

    using SkiaSharp;
    using SkiaSharp.Views.Forms;
    
    using Xamarin.Forms;
    
    namespace Test2 {
      public partial class MainPage : ContentPage {
        public static readonly SKCanvasView canvasView = new SKCanvasView();
        public MainPage() {
          InitializeComponent();
          canvasView.PaintSurface += OnCanvasViewPaintSurface;
          Content = canvasView;
        }
    
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e) {
          var surface = e.Surface;
          var canvas = surface.Canvas;
          var width = e.Info.Width;
          var height = e.Info.Height;
          var x = width/2.0f;
          var y = height/2.0f;
          var paint = new SKPaint();
          paint.TextSize = 14.0f;
          paint.IsAntialias = true;
          paint.Color = SKColors.Red;
          paint.IsStroke = false;
          var textBounds = new SKRect();
          var text = "Welcome to SkiaSharp";
          paint.MeasureText(text, ref textBounds);
          var textWidth = textBounds.Width + 4.0f;
          var textHeight = textBounds.Height + 2.0f;
          x -= textWidth/2.0f;
    
          canvas.DrawText(text, x, y, paint);
        }
      }
    }
    

    当选择Test2.UWP作为启动项目时,您将看到:

    enter image description here

    现在是啤酒的时候了!

相关问题