CommunityToolkit / CommunityToolkit/Windows

Crash when no DataTemplate is provided for ItemsSource Bindings in SettingsExpander

Open
#191 14 comments 0 reactions 0 assignees View on GitHub
bug components::controls::settingscontrols documentation
Dominant language
C#
Stars
1.1k
Forks
166
PR merge metrics
No merged PRs in 30d

Description

Not sure if this was discussed already somewhere else ...
But (now) I use the prerelease v8.0.230823-rc of this repository (Same issue occurred with last 'experimental' version 0.0.18 from the 'CommunityToolkit.Labs' package).

When binding an ObservableCollection to the ItemsSource attribute of a SettingsExpander, everything works as expected - when started from VisualStudio IDE.

However, when I start the installed App from Windows Start Menu the Application crashes with the first click on the Expander. The Windows Event Logger shows Application Error code 0xc000027b.

![WinUi3AppError](https://github.com/CommunityToolkit/Windows/assets/16986510/f4350071-d285-48af-9160-dc4edfe72e92)

Steps to reproduce:
---------------------

I am using Visual Studio 2022 Version 17.7.2 with AppSdk and Build Tools installed. Made a fresh Solution with "WinUI 3 Desctop - packaged" - Template.

My XAML:
```



```

My Code behind:
```
namespace WinUi3Test {
///
/// An empty window that can be used on its own or navigated to within a Frame.
///
public sealed partial class MainWindow : Window, INotifyPropertyChanged {

private ObservableCollection _mylist = new() { "first", "second" };
public ObservableCollection MyList { get => _mylist; set => SetProperty( ref _mylist, value); }

public MainWindow() {
this.InitializeComponent();
}

public event PropertyChangedEventHandler PropertyChanged;

private bool SetProperty([NotNullIfNotNull(nameof(newValue))] ref T field, T newValue, [CallerMemberName] string propertyName = null) {
if (EqualityComparer.Default.Equals(field, newValue)) {
return false;
}
field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return true;
}

private static int i = 0;
private void Button_Click(object sender, RoutedEventArgs e) {
MyList.Add("next" + i++);
}

private void Button_Click_1(object sender, RoutedEventArgs e) {
MyList.Clear();
}
}
}

```

My (Test) Project XML:
```


WinExe
net6.0-windows10.0.19041.0
10.0.17763.0
WinUi3Test
app.manifest
x86;x64;ARM64
win10-x86;win10-x64;win10-arm64
win10-$(Platform).pubxml
true
true



















true

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.