<syncfusion:ChromelessWindow x:Class="theRightDirection.PortalAnalyzer.Desktop.Controls.Basemaps.Basemaps"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:theRightDirection.PortalAnalyzer.Desktop.Controls.Basemaps"
xmlns:syncfusion="clr-namespace:Syncfusion.Windows.Shared;assembly=Syncfusion.Shared.WPF"
xmlns:chart="clr-namespace:Syncfusion;assembly=Syncfusion.SfChart.WPF"
xmlns:charts="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:legend="clr-namespace:theRightDirection.PortalAnalyzer.Controls.Legend;assembly=theRightDirection.PortalAnalyzer.Controls.Legend"
xmlns:enums="clr-namespace:theRightDirection.PortalAnalyzer.Controls.Legend.Enumerations;assembly=theRightDirection.PortalAnalyzer.Controls.Legend"
xmlns:drawing="clr-namespace:System.Drawing;assembly=System.Drawing"
xmlns:converters="clr-namespace:theRightDirection.PortalAnalyzer.Desktop.Controls.Basemaps.Converters"
xmlns:converters2="clr-namespace:theRightDirection.PortalAnalyzer.Desktop.Controls.Converters;assembly=theRightDirection.PortalAnalyzer.Desktop.Controls"
mc:Ignorable="d"
TitleFontSize="18"
Background="White"
TitleTextAlignment="Center"
CornerRadius="0"
BorderBrush="White"
BorderThickness="11"
AllowsTransparency="True"
TitleBarBackground="#81B844"
ShowInTaskbar="False"
ResizeBorderThickness="1"
ResizeBorderBrush="#686A76"
WindowStartupLocation="CenterScreen"
Name="basemapwindow"
syncfusion:SkinStorage.VisualStyle="Default" ResizeMode="NoResize" Icon="logo.ico" ShowActivated="False"
Title="Basemaps information" Height="600" Width="800">
<syncfusion:ChromelessWindow.Resources>
<converters2:ListCountToVisibilityConverter x:Key="listCountToVisibilityConverter" />
<converters:DeprecatedColorConverter x:Key="deprecatedColor"/>
<converters:DeprecatedFontWeightConverter x:Key="deprecatedFontWeight"/>
<DataTemplate x:Key="itemTemplate">
<StackPanel Orientation="Horizontal" ToolTip="{Binding Item.Tooltip}">
<CheckBox IsChecked="{Binding IsSeriesVisible, Mode=TwoWay}"/>
<Border BorderBrush="Black" BorderThickness="1" Width="17" Height="17" Margin="0 0 2 0">
<Rectangle Fill="{Binding Interior}"></Rectangle>
</Border>
<TextBlock FontWeight="{Binding Item.IsDeprecated, Converter={StaticResource deprecatedFontWeight}}" Foreground="{Binding Item.IsDeprecated, Converter={StaticResource deprecatedColor}}" Text="{Binding Label}" FontSize="10" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</syncfusion:ChromelessWindow.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<charts:SfChart Grid.Row="2" Margin="5" AreaBorderThickness="0">
<charts:SfChart.Legend>
<charts:ChartLegend ItemTemplate="{StaticResource itemTemplate}" Orientation="Vertical" DockPosition="Left" ToggleSeriesVisibility="True" CheckBoxVisibility="Visible"/>
</charts:SfChart.Legend>
<charts:PieSeries XBindingPath="Label" ItemsSource="{Binding Data}" YBindingPath="Count"/>
</charts:SfChart>
<legend:IconLegendItem Visibility="{Binding DataContext.WebmapWithOnlyBasemapCount, Converter={StaticResource listCountToVisibilityConverter}, ConverterParameter=0, ElementName=basemapwindow}" Grid.Row="0" LegendText="3 webmaps with only a basemap" IconColor="Red" IconFamily="{x:Static enums:IconFamily.Modern}" IconName="Map" Background="#686A76"/>
<legend:IconLegendItem Visibility="{Binding DataContext.DeprecatedBasemapsCount, Converter={StaticResource listCountToVisibilityConverter}, ConverterParameter=0, ElementName=basemapwindow}" Grid.Row="1" LegendText="90 webmaps with out of support basemap" IconColor="Red" IconFamily="{x:Static enums:IconFamily.Octicons}" IconName="Globe" Background="#686A76"/>
</Grid>
</syncfusion:ChromelessWindow>
I bind a viewmodel to the datacontext of this window. When I remove the Legend-part the nullreference dis appear. In the stacktrace I can only see that the nullreference happens in the SetLegendItem-method.
My hypothesis is that the WPF-elements are created before the data is bound to the viewmodel. So the binding to Data is a binding to an empty list of datapoints.
What can I do to avoid this error?