在winform項目,通過引用dll可以添加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;}
使用的winform項目中Resources.resx資源中的圖片,這里圖片還要求是png格式的才能成功加載,jpeg的則不行。