文字列依存プロパティ(SearchText)を更新すると、コレクション依存プロパティ(結果)を更新する必要があります。
マイコレクションDP:依存関係プロパティを別のものから更新する
public IEnumerable<string> Results{
get { return (IEnumerable<string>) GetValue(ResultsProperty); }
set { SetValue(ResultsProperty, value); }
}
public static readonly DependencyProperty ResultsProperty=
DependencyProperty.Register("Results", typeof(IEnumerable<string>), typeof(MainWindowVM), new UIPropertyMetadata(new List<string>()));
私は運でこれを試してみました。私はResults = ....ラインにブレークポイントを置き、決してヒットしませんでした。
public string SearchText{
get { return (string) GetValue(SearchTextProperty); }
set {
Results =
from T in Tree.GetPeople(value)
select T.FullName;
SetValue(SearchTextProperty, value);
}
}
public static readonly DependencyProperty SearchTextProperty=
DependencyProperty.Register("SearchText", typeof(string), typeof(MainWindowVM), new UIPropertyMetadata(""));
XAML:
<TextBox DockPanel.Dock="Top" Text="{Binding SearchValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<ListBox DockPanel.Dock="Top" ItemsSource="{Binding NameResults}" SelectedItem="{Binding Search}" />
-1、値の代入ではなくSetCurrentValueのに使用されますので、これは 'Second'プロパティにバインド解除されます(参照http://stackoverflow.com/質問/ 4230698/whats-the-difference-between-dependency-property-setvalue-setcurrentvalue)。 – Benlitz
真実今日、私はあなたを与えます。しかし、この回答が書かれた時点で、.NET Framework 3.5はSetCurrentValueメンバーを持たない最新のバージョンでした。 (ref:https://msdn.microsoft.com/en-us/library/system.windows.dependencyobject_members(v=vs.90).aspx) 近代化のためのコメントや追加回答が必要ですが、IMHO下降票を保証するものではありません。 –