我需要我的按钮颜色设置为系统颜色,即操作系统Windows风格被改变时,我的按钮颜色也相应变化,而不是固定的颜色风格。在WinForm里是这样写的
BackColor = System.Drawing.SystemColors.ControlText
但是WPF里没有System.Drawing.SystemColors.ControlText,只有Blue这样固定的颜色,怎么办?

解决方案 »

  1.   

    用c#做图像处理的时候需要用到System.Drawing.Bitmap。在WPF中显示图像的Image控件接受的数据源是ImageSource,因此使用System.Drawing.Bitmap进行图像处理之后要把System.Drawing.Bitmap转换成ImageSource,转换方法如下:
    System.Drawing.Bitmap m_Bitmap = new System.Drawing.Bitmap("c:\temp\test.jpg", false);
    IntPtr ip = m_Bitmap.GetHbitmap();
    BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
        ip, IntPtr.Zero, Int32Rect.Empty, 
        System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
    DeleteObject(ip);
    imageLarge.Source = bitmapSource;
    其中DeleteObject的声明如下:
    [DllImport("gdi32")]
    static extern int DeleteObject(IntPtr o);
    使用过System.Drawing.Bitmap后一定要用DeleteObject释放掉对象,不然内存不释放,很快系统内存就消耗光了。
      

  2.   

    自己搞定,在XAML中
    <SolidColorBrush x:Key="DefaultForeground" Color="{x:Static SystemColors.ControlTextColor}" />
      

  3.   

    我在C#里面是这样做的:
    System.Drawing.SystemColors.Control
      

  4.   

    我在C#里面是这样做的:
    System.Drawing.SystemColors.Control