2014-02-18 18 views
1

這是我的代碼它顯示你做錯了在BitmapImage的我想背景圖片添加到我的自定義消息框,但我無法得到它

CustomMessageBox messageBox = new CustomMessageBox() 
    { 
     Caption = "Congratulations", 
     Message = "you have won", 
     LeftButtonContent = "Play Again", 
     RightButtonContent = "FB Share", 
     VerticalAlignment = VerticalAlignment.Center, 
     Background = new BitmapImage(new Uri("/imaC:/Users/Rupak/Documents/Visual Studio 2012/Projects/sachin/sachin/image.png")), 
     Foreground = new SolidColorBrush(Colors.Black), 

    }; 
+0

嘗試不同的Uri(「/ image.png」,UriKind.RelativeOrAbsolute) - 如果圖像位於項目的根文件夾中。 – Romasz

+0

它顯示錯誤bitmapimage無法找到 – zap92

+0

我試過imagesource而不是bitmapimage它仍然顯示一些錯誤 – zap92

回答

1

錯誤,因爲CustomMessagebox.BacgroundBrush。你不能在那裏放置BitmapImage,ImageSource等。

,如果你把在那裏,它會工作的優良:

Background = new SolidColorBrush(Colors.Red), 

事實上存在的Windows Phone類似的ImageBrush但我測試了它不會與輕鬆的工作與CustomMessageBox:

ImageBrush mybrush = new ImageBrush() {ImageSource = new BitmapImage(new Uri("/Resources/firstImage.png", UriKind.Relative)) }; 

它不會因爲WPToolkit源代碼的工作有這樣的事情(License to code):

// (c) Copyright Microsoft Corporation. 
// This source is subject to the Microsoft Public License (Ms-PL). 
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. 
// All other rights reserved. 

// Insert the overlay. 
Rectangle overlay = new Rectangle(); 
Color backgroundColor = (Color)Application.Current.Resources["PhoneBackgroundColor"]; 
overlay.Fill = new SolidColorBrush(Color.FromArgb(0x99, backgroundColor.R, backgroundColor.G, backgroundColor.B)); 
_container = new Grid(); 
_container.Children.Add(overlay); 

正如你所看到的Grid覆蓋了Rectangle這是填充SolidColorBrush,而不是你設置的BrushImageBrush)。

+0

是的,它正在工作,當我使用背景=新SolidColorBrush(Colors.Red),但你能告訴我如何在消息框中使用背景圖片 – zap92

+0

我編輯了答案,並添加了它不可能的原因。 – Romasz

相關問題