亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 UWP 中的另一個值更改 DependencyProperty 值

如何從 UWP 中的另一個值更改 DependencyProperty 值

C#
眼眸繁星 2022-07-10 10:38:33
我正在 UWP 項目中創建一個 XAML 自定義控件,并且我將實現我已經發現可在 WPF 應用程序中使用的相同模式,以便在主 DependencyProperty 更改時一次性編輯控件的屬性。在下面的示例代碼中,我展示了當外部用戶更改 dp(名為“Color” )時如何更改SolidColorBrushdp(稱為“ColorBrush”) 。Color在 WPF 中,這是我實現的模式(正常工作):public partial class ColorViewer : UserControl{    // .ctor and other functions    public Color Color    {        get { return (Color)GetValue(ColorProperty); }        set        {            SetValue(ColorProperty, value);        }    }    public static readonly DependencyProperty ColorProperty =        DependencyProperty.Register("Color", typeof(Color), typeof(ColorViewer), new FrameworkPropertyMetadata(OnColorChanged));    public SolidColorBrush ColorBrush    {        get { return (SolidColorBrush)GetValue(ColorBrushProperty); }        set { SetValue(ColorBrushProperty, value); }    }    public static readonly DependencyProperty ColorBrushProperty =        DependencyProperty.Register("ColorBrush", typeof(SolidColorBrush), typeof(ColorViewer), null);    private static void OnColorChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)    {        var c = (Color) e.NewValue;        ColorViewer view = source as ColorViewer;        view.UpdateColorProperties(c);    }    private void UpdateColorProperties(Color c)    {        ColorBrush = new SolidColorBrush(c);        // Many other things...    } }特別是,我將一個FrameWorkPropertyMetadata(以方法作為參數)傳遞給設置“顏色”dp。帶著我的巨大(和悲傷)驚喜,我發現FrameworkPropertyMetadataUWP 平臺不提供該功能!如何在 UWP 中獲得相同的結果?
查看完整描述

1 回答

?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

它沒有這個,因為恕我直言,它比任何東西都膨脹,Uwp 有一個更簡單的ProperyMetadata類,它允許您設置 dp 的默認值,如果您想更深入,它還允許您設置一個調用的 CallBack值的變化。

.Register()函數中的最后一個參數是去哪里ProperyMetadata。

附帶說明一下,像SolidColorBrushdp 這樣的畫筆類型將很好地自動分組在“屬性”窗格上的“畫筆”組中,其他 dp 類型通常會列在“通用”組下


查看完整回答
反對 回復 2022-07-10
  • 1 回答
  • 0 關注
  • 83 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號