Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Exception if template without children is used

Open joneuhauser opened this issue 4 years ago • 0 comments

Tested in Avalonia 0.10.0-pre5, Windows 10, Visual Studio

Consider the following MWE:

ViewModelBase just implements INotifyPropertyChanged.

    class MainWindowViewModel : ViewModelBase
    {
        private EmptyViewModel tvm;
        public EmptyViewModel TextViewModel
        {
            get { return tvm; }
            set { tvm = value; OnPropertyChanged(); }
        }
        public MainWindowViewModel()
        {
            TextViewModel = new EmptyViewModel(); 
        }
    }
    public class EmptyViewModel : ViewModelBase
    {
    }
  <Window.DataTemplates>
    <DataTemplate DataType="{x:Type local:EmptyViewModel}"></DataTemplate>
  </Window.DataTemplates>
  <Grid>
    <ContentControl Content="{Binding TextViewModel}"/>
  </Grid>

Avalonia raises an exception here:

https://github.com/AvaloniaUI/Avalonia/blob/5feee900d4bdd0ca8da07acad168ff264d1a4b64/src/Markup/Avalonia.Markup.Xaml/Templates/TemplateContent.cs#L13-L17

which fails because

https://github.com/AvaloniaUI/Avalonia/blob/5feee900d4bdd0ca8da07acad168ff264d1a4b64/src/Markup/Avalonia.Markup.Xaml/Templates/DataTemplate.cs#L33

doesn't check for DataTemplate.Content != null.

At the very least, the error message could be a bit more verbose.

joneuhauser avatar Oct 22 '20 18:10 joneuhauser