为什么我的自定义 ListView 不能拥有自己的 xaml 文件?我有一个自定义按钮,它可以毫无问题地处理 xaml 文件,但不能处理我的 ListView。我想使用这种方法(而不是被迫创建一个放置在 Generic.xaml 文件中的样式)的主要原因是因为我想利用资源元素并将与 ListView 相关的所有资源放在xaml 文件:
public sealed partial class MyListView : ListView
{
public MyListView()
{
this.InitializeComponent();
}
}
这是关联的 xaml 文件:
<ListView
x:Class="App1.MyListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<ListView.Resources>
<!-- I would like to place all related resources here instead of having
them placed in external locations, and then have to open different files to find them. -->
</ListView.Resources>
</ListView>
最佳答案
虽然我希望这也能正常工作,但似乎存在这个问题并且 it is recommended to use the templated control instead .
我想问题是赋值编译器无法生成对控件的 Items
属性的有效赋值,它试图从元素的内容构造该属性。即使元素立即关闭,这似乎也是一个问题。
关于c# - 为什么自定义 ListView 不能拥有自己的 xaml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50709932/