【发布时间】:2011-10-07 00:12:18
【问题描述】:
我是 sliverlight 和 MVVM 的初学者。 我无法使用 MVVM 将另一个类的文本块属性绑定到 UI 类。
我的代码在这里。 请让我知道如何在下面的 Authentication.cs 中绑定 textblock 属性。
MainPage.xaml
<TextBlock Height="30" Margin="122,218,0,0" Name="textBlock3" Text="{Binding Path=ErrorStatus, Mode=TwoWay}" VerticalAlignment="Top" HorizontalAlignment="Left" Width="86" />
MainPage.xaml.cs
private Authentication authentication;
// Constructor
public MainPage()
{
InitializeComponent();
this.DataContext = authentication;
}
ViewModelBase.cs
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
身份验证.cs
public class Authentication : ViewModelBase
{
private string _ErrorStatus;
public string ErrorStatus
{
get
{
return _ErrorStatus;
}
set
{
_ErrorStatus = value;
NotifyPropertyChanged("ErrorStatus");
}
}
void Authenticate()
{
//Here, I write authentication code....
//After the authentication code, I want to change textBlock property depend on auth status.
//Please let me know how to write code.
}
}
【问题讨论】:
标签: silverlight windows-phone-7 mvvm