HeaderTemplate Design-Data Crashes XAML Designer

129 views Asked by At

I am building a UWP app and on a specific page of this app I have a ListView. I am binding this ListView's ItemsSource to a CollectionViewSource so that I can enable group headers. This is working just perfectly when I deploy the app to either an emulator or to actual hardware. However, in the XAML Designer, the page displays an empty list. I am using XML data sets to provide design-data on other pages of my app, but for some reason doing so on this page causes the XAML Designer to crash.

Sometimes the designer doesn't crash, and when that happens it renders the list items correctly, but the headers are all scaled way too big and are overlapping the other content on the page (note again, this only happens in the designer, it is fine at runtime). Attempting to interact with the designer when it is in this state causes the XDesProc.exe process to start eating 30%-40% CPU and promptly freezes both the Designer and Visual Studio itself until it either crashes or I manually kill the process in the Task Manager.

Looking in the Windows Event Viewer, I see the following stack trace:

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

[Remainder trimmed for brevity, but can be included on request]

I've found that if I remove the d:Source attribute from the CollectionViewSource OR remove the entire ListView.GroupStyle section, that the Designer no longer crashes, but of course in the case of the former I have no design data, (in fact, no visible text of any kind) and in the case of the latter I no longer have headers. Relevant XAML below:

<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>

My question is simply, what am I doing wrong? What about my GroupStyle.HeaderTemplate does the XAML Designer really not like? I would be fine with getting rid of the design data in favor of control ToString text placeholders, as long as I have something to look at when I'm designing the page (which right now, it's either design data or nothing and I'm not sure why). Any help either figuring out what's going wrong or pointing me in the direction of where to look would be greatly appreciated.

My code is all open source at https://github.com/Drakmyth/Hipstr with the page in question at https://github.com/Drakmyth/Hipstr/tree/master/Hipstr.Client/Views/Rooms

1

There are 1 answers

0
Shaun Hamman On BEST ANSWER

Posting this as an answer for those who may come across similar issues. As far as I can tell, the XAML Designer simply does not support design data when using a CollectionViewSource. It does not handle it properly and becomes very unstable when doing so. I have tried this again in VS2017, but with no improvement. I have resorted to just not using design data. Thankfully, with VS2017 supporting Edit and Continue for XAML, design data is not as crucial as it once was.