如何在UWP中更新一个依赖项属性

时间:2017-09-28 06:47:59

标签: c# xaml uwp

我有两个依赖项属性,当 First 中的值发生变化时,我想更新 Second - 例如给它临时值和更新UI,但是我不想破坏 Second 属性的绑定。

public bool Frist
{
    get { return (bool)GetValue(FristProperty); }
    set { SetValue(FristProperty, value); }
}

public static readonly DependencyProperty FristProperty =
    DependencyProperty.Register("Frist", typeof(bool), typeof(ItemControl), new PropertyMetadata(false, FirstUpdated));

private static void FirstUpdated(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var theControl = d as ItemsControl;
    // I would like to update also second dependency property here
    // for example if First == true, then Second = Overriden
    // else Second = the value from binding
}

public string Second
{
    get { return (string)GetValue(SecondProperty); }
    set { SetValue(SecondProperty, value); }
}

public static readonly DependencyProperty SecondProperty =
    DependencyProperty.Register("Second", typeof(string), typeof(ItemsControl), new PropertyMetadata(string.Empty));

我已经看过WPF的各种样本,但似乎UWP中缺少一些东西。有什么选择?

0 个答案:

没有答案