私のアイテムの表示を自分のウィンドウの右側に表示しようとしています。最初にウィンドウを初期化すると、すべてが完全に機能します。私がしていることは、ファイルを逆シリアル化してObservableCollection<Model.Resources>
を取得することです。私のリストのすべてのアイテムがListBoxに表示されます。 [リソースの追加]ウィンドウに入り、さらにリソースを追加すると、これらのオブジェクトがファイルにシリアル化されます。追加が終わったら、refresh()
というメソッドを呼び出して、いくつかのファイルを非直列化して更新します。ObservableCollection<Model.Resources>
私がそれを終えると、私のプログラムを再起動するまでListBoxは更新されません。私のWindowクラスのリストボックスが非直列化後に更新されない
<ListBox x:Name="itemList" Grid.Column="1" HorizontalAlignment="Stretch" Margin="7,23,6,0" Grid.Row="1" VerticalAlignment="Stretch" Background="#324251" ItemsSource="{Binding Path=resources}" FontSize="16" Foreground="Wheat"/>
関連するコード:
public partial class GlowingEarth : Window, INotifyPropertyChanged
{
private ObservableCollection<Model.Etiquette> _tags;
private ObservableCollection<Model.Resource> _resources;
private ObservableCollection<Model.Type> _types;
public ObservableCollection<Model.Etiquette> tags
{
get
{
return _tags;
}
set
{
_tags = value;
OnPropertyChanged("tags");
}
}
public ObservableCollection<Model.Resource> resources
{
get
{
return _resources;
}
set
{
_resources = value;
OnPropertyChanged("resources");
}
}
public ObservableCollection<Model.Type> types
{
get
{
return _types;
}
set
{
_types = value;
OnPropertyChanged("types");
}
}
private BinaryFormatter fm;
private FileStream sm = null;
private string path;
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
public GlowingEarth()
{
InitializeComponent();
tags = new ObservableCollection<Model.Etiquette>();
resources = new ObservableCollection<Model.Resource>();
types = new ObservableCollection<Model.Type>();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
refresh();
}
public void refresh()
{
path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "typeList");
if (File.Exists(path))
{
fm = new BinaryFormatter();
sm = File.OpenRead(path);
_types = (ObservableCollection<Model.Type>)fm.Deserialize(sm);
sm.Dispose();
}
else
{
return;
}
path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tagList");
if (File.Exists(path))
{
fm = new BinaryFormatter();
sm = File.OpenRead(path);
_tags = (ObservableCollection<Model.Etiquette>)fm.Deserialize(sm);
sm.Dispose();
}
else
{
return;
}
path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "reslist");
if (File.Exists(path))
{
fm = new BinaryFormatter();
sm = File.OpenRead(path);
_resources = (ObservableCollection<Model.Resource>)fm.Deserialize(sm);
sm.Dispose();
}
else
{
return;
}
InitializeComponent();
this.DataContext = this;
}
はあなたが私に教えてくださいすることができ、地球上で何が起こっている、そしてなぜISN」リストボックスを持っている私の窓の
XAML私のリスト更新?それはOnPropertyChanged("resources");
を呼び出すことはありませんrefresh()
方法で
私の親切な先生、あなたは正しいです!ありがとうございます! – Riki
@Riki、答えがあなたを助けたら、それを受け入れてください – ASh