这是我的代码,它在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 :(得分:1)
你做错了,因为CustomMessagebox.Bacground
是Brush
。你不能把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
,而不是您设置的Brush
(ImageBrush
)。