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

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

如何使用Properties.Resources中的圖像從WPF中的代碼隱藏動態更改圖像源?

如何使用Properties.Resources中的圖像從WPF中的代碼隱藏動態更改圖像源?

如何使用Properties.Resources中的圖像從WPF中的代碼隱藏動態更改圖像源?我有一個WPF應用程序,需要向用戶提供有關內部狀態的反饋。設計是有三個圖像,稱為紅色,黃色和綠色。其中一個圖像將根據狀態一次顯示。以下是要點:這三個圖像位于代碼隱藏中的Properties.Resources中一次只能顯示一個圖像。狀態更改來自代碼隱藏中的進程,而不是來自用戶。我想綁定一個圖像控件,以便我可以從代碼隱藏更改圖像。我假設我需要一個圖像轉換器來將JPG圖像更改為圖像源,例如:[ValueConversion(typeof(System.Drawing.Bitmap), typeof(ImageSource))]public class BitmapToImageSourceConverter : IValueConverter{     public object Convert(object value, Type targetType, object parameter, CultureInfo culture)     {         var bmp = value as System.Drawing.Bitmap;         if (bmp == null)             return null;         return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(                     bmp.GetHbitmap(),                     IntPtr.Zero,                     Int32Rect.Empty,                     BitmapSizeOptions.FromEmptyOptions());     }     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)     {         throw new NotSupportedException();     }}我更喜歡在初始化期間轉換圖像一次并保留圖像源列表。我還假設我需要一個依賴屬性來綁定控件,但我不知道如何使用這個圖像源列表來設置它:    // Dependancy Property for the North Image     public static readonly DependencyProperty NorthImagePathProperty         = DependencyProperty.Register(             "NorthImagePath",             typeof(ImageSource),             typeof(MainWindow),             new PropertyMetadata("**Don't know what goes here!!!**"));     // Property wrapper for the dependancy property     public ImageSource NorthImagePath     {         get { return (ImageSource)GetValue(NorthImagePathProperty); }         set { SetValue(NorthImagePathProperty, value); }     }
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 491 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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