好吧我一直在關注這個問題,我錯過了一些東西,我無法弄清楚什麼。最終,我試圖設置數據綁定,這樣我就可以更新值,以便隨時顯示,但對於我的生活而言,這不起作用。C#XAML數據綁定在財產變更時沒有效果
的XAML是:
<TextBox x:Name="textBox" HorizontalAlignment="Left"
Height="37" Margin="85,38,0,0" TextWrapping="Wrap"
Text="{Binding Path=TBBind}" VerticalAlignment="Top"
Width="121" />
請注意,我有{Binding Path=TBBind}
集。
後面的代碼是:
using System.ComponentModel;
using System.Windows;
namespace Databinding_Practice_2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
TBBind = "test";
}
private string _tBBind;
public string TBBind
{
get { return _tBBind; }
set
{
if (value != _tBBind)
{
_tBBind = value;
OnPropertyChanged("TBBind");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string property)
{
MessageBox.Show("OnPropertyChanged triggered");
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
}
}
幫助我OBI-W ....哦,等等,幫助我的人!
謝謝,我知道這是我失蹤的愚蠢! –