以下uri有什麼問題?圖像源上的Uri格式化
bmi.UriSource = (new Uri(@"/Assets/Image.png", UriKind.Relative));
凡bmi
是BitmapImage
。
我有設置爲Embedded Resource的圖像的構建操作。
以下uri有什麼問題?圖像源上的Uri格式化
bmi.UriSource = (new Uri(@"/Assets/Image.png", UriKind.Relative));
凡bmi
是BitmapImage
。
我有設置爲Embedded Resource的圖像的構建操作。
找到它;
bmi.UriSource = (new Uri("ms-appx:/Assets/Logo.png"));
並將構建操作設置爲內容。 RT中沒有相對URI。
WPF需要使用資源構建操作(或內容構建操作)來使用Uris。對於二進制數據(如圖像),使用二進制。
如果你使用單個項目作爲你的代碼(單個DLL),你可以跳過'/ MYAPPLICATIONNAME; component /',只是使用「Assets/Image.png」作爲相對Uri。
嗯我得到的錯誤'給定的System.Uri無法轉換成一個Windows.Foundation.Uri'使用'bmi.UriSource =(新Uri(@「/ Assets/Image.png」,UriKind.Relative)) ;'並建立操作設置爲內容。 – windowskm 2013-04-24 19:42:53
那麼你應該使用'bmi.UriSource = new Windows.Foundation.Uri(@「/ Assets/Image.png」);' – 2013-04-24 20:24:47
每個控件或頁面都有一個BaseUri
屬性,您可以使用該屬性爲資產構建適當的uri。
下面是一個例子:
imageIcon.Source = new BitmapImage(new Uri(this.BaseUri, "Assets/file.gif"));
// Or use the base uri from the imageIcon, same thing
imageIcon.Source = new BitmapImage(new Uri(imageIcon.BaseUri, "Assets/file.gif"));
這是WinRT的,不是WPF,對不對?如果是這樣,你應該使用適當的標籤。 – Clemens 2013-04-24 19:55:30
抱歉習慣的力量,你是對的。固定。 – windowskm 2013-04-24 19:58:05