forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Always raise binding value changed when PropertyChanged event is…
… raised
- Loading branch information
1 parent
fe26b2f
commit efdd19c
Showing
4 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/Uno.UI.RuntimeTests/Tests/BindingTests/BindingShouldBeAppliedOnPropertyChangedEvent.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Page | ||
x:Class="Uno.UI.RuntimeTests.Tests.BindingShouldBeAppliedOnPropertyChangedEvent" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Uno.UI.RuntimeTests.Tests" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Page.Resources> | ||
<local:BindingShouldBeAppliedOnPropertyChangedEventConverter x:Key="MyConverter" /> | ||
</Page.Resources> | ||
|
||
<StackPanel> | ||
<TextBlock x:Name="myTb" Text="{Binding Holder, Converter={StaticResource MyConverter}}" x:FieldModifier="public" /> | ||
</StackPanel> | ||
</Page> |
49 changes: 49 additions & 0 deletions
49
...o.UI.RuntimeTests/Tests/BindingTests/BindingShouldBeAppliedOnPropertyChangedEvent.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.ComponentModel; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Data; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests; | ||
|
||
public class BindingShouldBeAppliedOnPropertyChangedEventConverter : IValueConverter | ||
{ | ||
public int ConvertCount { get; private set; } | ||
|
||
public object? Convert(object? value, Type targetType, object parameter, string language) | ||
{ | ||
ConvertCount++; | ||
return value is BindingShouldBeAppliedOnPropertyChangedEventValueHolder holder ? holder.Value : null; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, string language) | ||
=> throw new NotSupportedException(); | ||
} | ||
|
||
public sealed partial class BindingShouldBeAppliedOnPropertyChangedEvent : Page | ||
{ | ||
public BindingShouldBeAppliedOnPropertyChangedEvent() | ||
{ | ||
this.InitializeComponent(); | ||
this.DataContext = new BindingShouldBeAppliedOnPropertyChangedEventVM(); | ||
} | ||
} | ||
|
||
public class BindingShouldBeAppliedOnPropertyChangedEventVM : INotifyPropertyChanged | ||
{ | ||
public BindingShouldBeAppliedOnPropertyChangedEventValueHolder Holder { get; set; } = new(); | ||
|
||
public event PropertyChangedEventHandler? PropertyChanged; | ||
|
||
public void Increment() | ||
{ | ||
Holder.Value++; | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Holder))); | ||
} | ||
} | ||
|
||
public class BindingShouldBeAppliedOnPropertyChangedEventValueHolder | ||
{ | ||
public int Value { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters