【发布时间】:2015-01-10 09:13:49
【问题描述】:
我有一些问题,我只能在我的 Mainwindow() 方法中更新我的 gui。并且无法真正弄清楚为什么它不能在事件中更改 gui。我也使用绑定和视图模型类。
所以当我走出主窗口时,我的绑定似乎停止工作?
有什么想法可能是错的吗?
谢谢!
public partial class MainWindow : Window
{
public ObservableCollection<ChessPiece> ItemX { get; set; }
public MainWindow()
{
ItemX = new ObservableCollection<Chess>();
InitializeComponent();
DataContext = ItemX ;
ItemX.Add(new Chess() { PosX = 0, PosY = 0, Type_ = Piece.Farmer, Player_ = PiecePlayer.Black });
ItemX.Add(new Chess() { PosX = 0, PosY = 1, Type_ = Piece.Farmer, Player_ = Player.Black });
ItemX.ElementAt(1).PosX = 5; //This works perfect, my GUI changes!
}
public void ChessBoardClick(object sender, MouseButtonEventArgs e)
{
ItemX.ElementAt(0).PosX = 3; //Wont work, but the values inside ItemX changes.
}
【问题讨论】:
-
你说我的GUI改变了,但是GUI在哪里呢?它与什么有关?
Chess类是否正确实现了INotifyPropertyChanged?
标签: c# wpf user-interface binding