1.创建WPF项目
2.创建WinForm项目并添加WPF相关的引用
但是如果直接在winform的项目中添加wpf窗体还是有部分问题,图片的显示。
直接在XAML界面中用Source属性设置图片会出现错误。必须通过后台代码的方式来实现。
image1.Source = GetImageIcon(global::Com.JunXinEastern.Jcj.Properties.Resources.loginImg);
Image image = new Image();
image.Source = GetImageIcon(global::Com.JunXinEastern.Jcj.Properties.Resources.login_csyj1);
ImageBrush ib = new ImageBrush();
ib.ImageSource = image.Source;
grid1.Background = ib;
private static BitmapImage GetImageIcon(System.Drawing.Bitmap bitmap)
{
BitmapImage bitmapImage = new BitmapImage();
try
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bitmap.Save(ms, bitmap.RawFormat);
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze();
}
catch (Exception ex)
{
//Utilities.ShowExceptionMessage(ex);
}
return bitmapImage;
}
3.WPF窗体显示相关设置
namespace Mask
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow(double height, double width)
{
InitializeComponent();
this.WindowStyle = WindowStyle.None;//设置窗体无边框
this.AllowsTransparency = true;//窗体支持透明度
this.Opacity = 0.6;//设置透明度为0.4
this.Height = height; //设置窗体高度
this.Width = width; // 设置窗体宽度
}
/// <summary>
/// 自定义属性
/// </summary>
public bool showflg { get; set; }
}
}
版权声明:本文为twoeagles原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。