UI.WPF.Modern
UI.WPF.Modern copied to clipboard
[Bug] AutoSuggestBox.Text绑定疑似有点问题
Describe the bug
绑定到属性时,更新AutoSuggestBox
的文本,无法更新属性的值
To Reproduce Steps to reproduce the behavior:
<!-- test.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" PrivateAssets="all" />
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.9.30" />
</ItemGroup>
</Project>
<!-- MainWindow.xaml -->
<Window x:Class="test.MainWindow"
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:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:local="clr-namespace:test"
mc:Ignorable="d"
Title="MainWindow"
Height="450"
Width="800">
<StackPanel>
<ui:AutoSuggestBox
Text="{Binding Input1, UpdateSourceTrigger=PropertyChanged}">
<ui:AutoSuggestBox.QueryIcon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Search}"/>
</ui:AutoSuggestBox.QueryIcon>
</ui:AutoSuggestBox>
<TextBox Text="{Binding Input2, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
</Window>
// MainWindow.xaml.cs
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
namespace test;
public partial class MainWindow : Window, INotifyPropertyChanged
{
public string? Input1 { get; set; }
public string? Input2 { get; set; }
public MainWindow()
{
DataContext = this;
InitializeComponent();
Task.Run(() =>
{
while (true)
{
Task.Delay(2000).Wait();
Console.WriteLine("1:" + Input1 + "; 2:" + Input2);
}
});
}
#pragma warning disable CS0067
public event PropertyChangedEventHandler? PropertyChanged;
}
用了PropertyChanged.Fody
包生成属性更新触发PropertyChanged
的代码
分别更改AutoSuggestBox
和TextBox
,输出只有Input2
的值,Input1
始终为空
Expected behavior
控制台应分别输出Input1
和Input2
的值
Screenshots If applicable, add screenshots to help explain your problem.
图
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
windows 10 (19045.4894)
Additional context Add any other context about the problem here.
- 用元素名(
ElementName=
)绑定AutoSuggestBox.Text
到TextBlock.Text
的话,TextBlock
可正常更新 - 初始值能更新到控件上(后面的1111是我自己加的)