其实我有一些UWP项目,需要重构一些冗余代码。
在我的 GUI 中,这部分代码有很多次
<ListView ItemsSource="{Binding Model.EstadoValidar.ListaInconsistencias }" Grid.Row="9">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Descripcion}" Height="Auto" TextWrapping="Wrap"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
并且需要将其转换为自定义控件。
我使用 WPF 控件库 (.NET Framework) 添加了一个名为控件的新项目,它无法识别ListView或GridView对象。
必须使用什么样的项目来构建我的客户控件?
实际使用 VS 2017 15.3,项目目标为 .NET 4.6.2 / Standard 1.4
UWP 应用不能引用WPF Control Library. 只有 WPF 应用程序可以。
您不能制作可在 UWP 和 WPF 上使用的自定义控件。忘记这个吧。UWP 和 WPF 具有无法共享的不同 XAML 堆栈。
如果你想创建一个可重用的 UWP 控件,你可以创建一个Class Library (Universal Windows)项目:http : //www.dotnetcurry.com/windowsapp/930/create-user-control-xaml-csharp