Browse Source
Merge pull request #12193 from AvaloniaUI/fixes/11220-selectedvaluebinding-null-item
Fix SelectedValueBinding with items defined in XAML
pull/12206/head
Max Katz
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
17 additions and
3 deletions
-
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
-
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_SelectedValue.cs
|
|
|
@ -1395,10 +1395,8 @@ namespace Avalonia.Controls.Primitives |
|
|
|
|
|
|
|
public object Evaluate(object? dataContext) |
|
|
|
{ |
|
|
|
dataContext = dataContext ?? throw new ArgumentNullException(nameof(dataContext)); |
|
|
|
|
|
|
|
// Only update the DataContext if necessary
|
|
|
|
if (!dataContext.Equals(DataContext)) |
|
|
|
if (!Equals(dataContext, DataContext)) |
|
|
|
DataContext = dataContext; |
|
|
|
|
|
|
|
return GetValue(ValueProperty); |
|
|
|
|
|
|
|
@ -268,6 +268,22 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
Assert.True(called); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Handles_Null_SelectedItem_When_SelectedValueBinding_Assigned() |
|
|
|
{ |
|
|
|
// Issue #11220
|
|
|
|
var items = new object[] { null }; |
|
|
|
var sic = new SelectingItemsControl |
|
|
|
{ |
|
|
|
ItemsSource = items, |
|
|
|
SelectedIndex = 0, |
|
|
|
SelectedValueBinding = new Binding("Name"), |
|
|
|
Template = Template() |
|
|
|
}; |
|
|
|
|
|
|
|
Assert.Null(sic.SelectedValue); |
|
|
|
} |
|
|
|
|
|
|
|
private static FuncControlTemplate Template() |
|
|
|
{ |
|
|
|
return new FuncControlTemplate<SelectingItemsControl>((control, scope) => |
|
|
|
|