c# - 为什么自定义 ListView 不能拥有自己的 xaml 文件?

标签 c# xaml uwp uwp-xaml

为什么我的自定义 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/

相关文章:

uwp - 为什么有些 UWP 项目有 project.json 而有些则没有?

c# - 奇怪的动态类型参数问题

c# - 无法将类型 'double' 隐式转换为 'string'

c# - Xamarin.Forms 如何将多个页面的 BindingContext 设置为同一个 ViewModel?

wpf - WPF 样式和派生类无法识别属性

windows - 用于针对 UWP/Centennial 项目进行构建的映射文件是什么?如何制作它们?

c# - 在 CommandBar 的 SecondaryCommand 上设置图标

c# - 在 .net 2.0 中的两个流之间复制

javascript - 是否可以在 spotfire 文本区域显示图像/消息以等待数据加载?

c# - Xamarin布局如何在屏幕的左下角和右下角放置标签