使用Prism库我已经设置了继承BindableBase的模型(INotiftyPropertyChanged)。
然后在ViewModel中,在构造函数中,我创建了一个ReadConnections类的新对象,它将从本地XML文件返回一个连接名列表。
然后我从ReadConnections类中的方法GetIdNode设置Connections属性。
最后,我将Listbox ItemSource绑定到Connections属性。当我运行应用程序时,列表框没有填充任何列表框项。我不确定绑定的ItemSource是否正确,我以前从未将任何内容绑定到列表框。
模特课程:
public class LoginDialogModel : BindableBase
{
private List<string> _connections;
public List<string> Connections
{
get { return _connections; }
set { _connections = value; }
}
}
ViewModel类构造函数:
public LoginDialogVM()
{
ReadConnections read = new ReadConnections();
LoginModel.Connections = read.GetIdNodes();
}
XAML:
<ListBox HorizontalAlignment="Left" Height="247" Margin="10,10,0,0"
VerticalAlignment="Top" Width="135" ItemsSource="{Binding LoginModel.Connections}"/>
答案 0 :(得分:1)
你的属性(BindableBase继承)应该是这样的
public class LoginDialogModel : BindableBase
{
private List<string> _connections;
public List<string> Connections
{
get { return _connections; }
set { SetProperty(ref _connections,value); }
}
}
如您所见,SetProperty方法负责NotifyProperty