我有一個字符串依賴屬性(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,這將打破對'秒'屬性綁定的SetValue,因爲將被用來代替SetCurrentValue(見http://stackoverflow.com/問題/ 4230698 /什麼最差之間的依賴關係,財產的setValue-setcurrentvalue)。 – Benlitz 2014-05-12 09:42:11
今天是真的,我會給你的。但是,在編寫此答案時,.NET Framework 3.5是最新版本,沒有SetCurrentValue成員。 (ref:https://msdn.microsoft.com/en-us/library/system.windows.dependencyobject_members(v=vs.90).aspx) 很值得現代化的評論或額外的答案,但恕我直言它不保證否決票。 – 2015-02-14 21:18:32