在winform中使用wpf窗体
生活随笔
收集整理的這篇文章主要介紹了
在winform中使用wpf窗体
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在winform項(xiàng)目,通過(guò)引用dll可以添加WPF窗體,如下
?
但是如果直接在winform的項(xiàng)目中添加wpf窗體還是有部分問(wèn)題,圖片的顯示。
直接在XAML界面中用Source屬性設(shè)置圖片會(huì)出現(xiàn)錯(cuò)誤。必須通過(guò)后臺(tái)代碼的方式來(lái)實(shí)現(xiàn)。
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項(xiàng)目中Resources.resx資源中的圖片,這里圖片還要求是png格式的才能成功加載,jpeg的則不行。
轉(zhuǎn)載于:https://www.cnblogs.com/KQNLL/p/9208810.html
總結(jié)
以上是生活随笔為你收集整理的在winform中使用wpf窗体的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Openresty编写Lua代码一例
- 下一篇: 软件构造 第五章第一节 可复用性的度量