ObservableStackの実装でどこが間違っているのかを指摘できますか? XAMLはスタックに含まれている情報がどのようにUIに表示されていないかに関わらず、バインドに失敗しています。 ViewModelのプロパティの型をObservableStackからObservableCollectionに変更するだけで、UI要素が表示されます。これは実装だと思います。ObservableStackに関する問題<T>実装とXAMLバインディング
私の要素がスタックオーダーではなくコレクションオーダーでUIに表示されるように、これを使用します。
事前のお手伝いがあります。
public class ObservableStack<T> : INotifyPropertyChanged, INotifyCollectionChanged, ICollection , IEnumerable<T>, IEnumerable , IReadOnlyCollection<T>
{
ObservableCollection<T> _coll = new ObservableCollection<T>();
public ObservableStack()
{
_coll.CollectionChanged += _coll_CollectionChanged;
}
public ObservableStack(IEnumerable<T> items) : base()
{
foreach (var item in items)
{
Push(item);
}
}
private void _coll_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnCollectionChanged(e);
}
public void Push(T item)
{
_coll.Insert(0, item);
}
public void Pop()
{
_coll.RemoveAt(0);
}
public T Peek
{
get { return _coll[0]; }
}
public int Count
{
get
{
return ((ICollection)_coll).Count;
}
}
public bool IsSynchronized
{
get
{
return ((ICollection)_coll).IsSynchronized;
}
}
public object SyncRoot
{
get
{
return ((ICollection)_coll).SyncRoot;
}
}
public void CopyTo(Array array, int index)
{
((ICollection)_coll).CopyTo(array, index);
}
public IEnumerator GetEnumerator()
{
return ((ICollection)_coll).GetEnumerator();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return ((IEnumerable<T>)_coll).GetEnumerator();
}
#region INotifyPropertyChanged
protected void OnPropertyChanged([CallerMemberName] string caller = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(caller));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region INotifyCollectionChanged
public event NotifyCollectionChangedEventHandler CollectionChanged;
protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
CollectionChanged?.Invoke(this, e);
}
#endregion
}
"XAMLが何らかの方法でバインドするのに失敗していますか?OK、おそらくあなたが知っているように、失敗したXAMLを表示できますか? DataContextの割り当て方法は?そして、ビューモデル?最小限で、完全で、検証可能なものなど、あなたは知っていますか?あなたは、バインディング自体、またはその(意図された)ソースまたはターゲットについて正確には何も教えていません。しかし、あなたは私たちに、それが間違っていることを教えてほしい。あなたの推測は私のものと同じくらい良いです。 –
技術的には、このObservableStackは、適切なフレームワークを対象とする移植可能なアセンブリに置かれた場合、WPFとUWPで動作します。 – ibebbs
@ PeterTorr-MSFT、私はibebbsに同意します。両地域のSOメンバーがコメントできず、また恩恵を受けられる理由もありません。 – Cleve