gpt4 book ai didi

wpf - WPF 中的文本框绑定(bind)

转载 作者:行者123 更新时间:2023-12-01 00:06:33 25 4
gpt4 key购买 nike

我在 XAML 文件中有一个文本框,在更改文本框中的文本时,不会调用 prop setter。我能够在 ProjectOfficer 文本框中获取值,但无法更新它。我正在使用 MVVM 模式

下面是我的代码 XAML

 TextBox Text="{Binding Path=Officer,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
x:Name="ProjectOfficer"/>

View 模型.cs
    public Staff Officer 
{
get
{
return __con.PrimaryOfficer ;
}
set
{
_con.PrimaryOfficer = value;
_con.PrimaryOfficer.Update(true);
}
}

员工.cs
public class Staff : EntityBase 
{
public Staff();

public string Address { get; }
public string Code { get; set; }
public override void Update();
}

谢谢

最佳答案

您正在将 TextBox 上的 string 类型的属性绑定(bind)到 ViewModel 上的 Officer 类型的属性。我希望 setter 不会被调用,因为 WPF 无法进行转换。

如果您在 Visual Studio 中检查输出窗口,您可能会看到此属性的绑定(bind)错误。

关于wpf - WPF 中的文本框绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1171826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com