HeaderTemplate Design-Data 崩溃 XAML 设计器

HeaderTemplate Design-Data Crashes XAML Designer

我正在构建一个 UWP 应用程序,在这个应用程序的特定页面上我有一个 ListView。我将此 ListView 的 ItemsSource 绑定到 CollectionViewSource,以便我可以启用组 headers。当我将应用程序部署到模拟器或实际硬件时,这工作得很好。但是,在 XAML Designer 中,页面显示一个空列表。我正在使用 XML 数据集在我的应用程序的其他页面上提供 design-data,但出于某种原因在此页面上这样做会导致 XAML Designer 崩溃。

有时设计器不会崩溃,当发生这种情况时它会正确呈现列表项,但是 headers 都缩放得太大并且与页面上的其他内容重叠(再次注意,这只发生在设计器中,在运行时没问题)。在此状态下尝试与设计器交互会导致 XDesProc.exe 进程开始消耗 30%-40% CPU 并立即冻结设计器和 Visual Studio 本身,直到它崩溃或者我在任务管理器中手动终止进程。

查看 Windows 事件查看器,我看到以下堆栈跟踪:

Application: XDesProc.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException at Windows.UI.Xaml.Hosting.XamlUIPresenter.Render() at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.Views.WindowsUIXamlImageHost.RenderWorker() at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.Views.WindowsUIXamlImageHost+RenderScheduler.OnRender(System.Object) at

[为简洁起见删减了剩余部分,但可根据要求包含]

我发现,如果我从 CollectionViewSource 中删除 d:Source 属性 删除整个 ListView.GroupStyle 部分,设计器将不再崩溃,但是对于前者,我当然没有设计数据(事实上,没有任何类型的可见文本),对于后者,我不再有 headers。相关XAML如下:

<Page.Resources>
    <ResourceDictionary>
        <CollectionViewSource x:Name="GroupedRoomsSource"
                              Source="{x:Bind ViewModel.RoomGroups, Mode=OneWay}"
                              IsSourceGrouped="True"
                              ItemsPath="Rooms"
                              d:Source="{Binding RoomGroups, Source={d:DesignData Source=/SampleData/RoomsViewModelSampleData.xaml}}"/>
    </ResourceDictionary>
</Page.Resources>

<ListView x:Name="RoomList"
          Grid.Row="0"
          ItemsSource="{Binding Source={StaticResource GroupedRoomsSource}}">
    <ListView.GroupStyle>
        <GroupStyle HidesIfEmpty="True">
            <GroupStyle.HeaderTemplate>
                <DataTemplate x:DataType="models:RoomGroup">
                    <TextBlock Text="{x:Bind Header}"
                               Foreground="White"
                               FontSize="24" />
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>
    </ListView.GroupStyle>
    <ListView.ItemTemplate>
        <DataTemplate x:DataType="models:Room">
            <StackPanel>
                <TextBlock Text="{x:Bind Name}"
                           Foreground="White" />
                <TextBlock Text="{x:Bind Team.Name}"
                           Foreground="LightGray"
                           FontSize="10" />
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

我的问题很简单,我做错了什么? XAML设计师真的不喜欢我的GroupStyle.HeaderTemplate吗?只要我在设计页面时有东西要看(现在,它要么是设计数据,要么什么都不是,我是不知道为什么)。任何帮助找出问题所在或指出我在哪里看的方向的帮助都将不胜感激。

我的代码全部开源在https://github.com/Drakmyth/Hipstr with the page in question at https://github.com/Drakmyth/Hipstr/tree/master/Hipstr.Client/Views/Rooms

发布此作为可能遇到类似问题的人的答案。据我所知,XAML Designer 在使用 CollectionViewSource 时根本不支持设计数据。它没有正确处理它并且在这样做时变得非常不稳定。我在 VS2017 中再次尝试过,但没有任何改进。我已经求助于不使用设计数据。值得庆幸的是,VS2017 支持 XAML 的“编辑并继续”,设计数据不再像以前那么重要了。