2016-12-15 13 views
0

私のGird内でComboBoxを更新したいと考えています。私は何らかのイベントシステムが必要だと思っています。DataContext:comboBoxのItemSourceを更新する

次のように私はそれをバインドされました:次のように

<ComboBox Name="ScreenLocations" Grid.Row="1" Margin="0,0,0,175" ItemsSource="{Binding Path=CurrentPlayer.CurrentLocation.CurrentDirections}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path= Location}"/> 

私xaml.csは次のとおりです。

public partial class MainWindow : Window 
{ 
    GameSession _gameSession; 

    public MainWindow() 
    { 
     InitializeComponent(); 

     _gameSession = new GameSession(); 
     DataContext = _gameSession; 

    } 
} 

私はCurrentDirectionsプロパティを変更できるようにし、それがで更新したいですUI。あなただけのクラス場所にSystem.ComponentModel.INotifyPropertyChangedインタフェースを実装する必要が

public class Location 
{ 
    public int ID { get; set; } 
    public string Name { get; set; } 
    public string Description { get; set; }  
    public Quest[] AvailableQuests { get; set; } 
    public Monster[] LocationMonsters { get; set; } 
    public Location[] CurrentDirections { get; set; } 


    public Location(string name, string description, Quest[] availableQuests, int id) 
    { 
     Name = name; 
     Description = description;   
     AvailableQuests = availableQuests; 
     ID = id; 
     CurrentDirections = new Location[] { }; 
     LocationMonsters = new Monster[] { }; 
     AvailableQuests = new Quest[] { }; 
    } 
} 

答えて

0

:私はそれがバインドされてい

クラスとプロパティがあります。これにより、関心のある関係者(バインドされたComboBoxなど)が変更を検出するためにサブスクライブできるPropertyChangedイベントを定義し、CurrentDirectionsを次のように再実装することができます。

完全性のために、このインターフェイスをPlayerで実装することを検討してください。

+0

は、INotiftyPropertyChangedを調べて、私が望むものを達成しました。ありがとうございました。 –

関連する問題