【发布时间】:2018-05-01 04:31:06
【问题描述】:
源代码:
class Cons
{
public Cons()
{
BaseDir = AppDomain.CurrentDomain.BaseDirectory;
SetProperty();
}
private void SetProperty()
{
NowPlaying = "Hello";
}
public string NowPlaying{get; set; }
}
public partial class MainWindow
{
Cons Resources = new Cons()
public MainWindow()
{
txbl.DataContext = Resources;
Resources.NowPlaying = "NoHello";
}
}
还有一个文本块<Textblock x:Name="txbl" Text="{Binding NowPlaying, Mode=TwoWay}"/>
当我在 MainWindow 构造函数中设置 NowPlaying 属性时,该属性更改为“NoHello”,但即使我设置绑定模式 = TwoWay,TextBlock 文本属性仍然是 Hello
【问题讨论】:
-
我不知道你做错了什么。我复制了你的代码,它工作正常。顺便说一句,您不需要
binding mode = TwoWay,因为无法从 GUI 更改 TextBlock