在winform中使用wpf窗体
生活随笔
收集整理的這篇文章主要介紹了
在winform中使用wpf窗体
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在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的則不行。
轉載于:https://www.cnblogs.com/KQNLL/p/9208810.html
總結
以上是生活随笔為你收集整理的在winform中使用wpf窗体的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Openresty编写Lua代码一例
- 下一篇: 软件构造 第五章第一节 可复用性的度量