Is it possible to create my own Custom MessageBox where I can be able to add images instead of only strings?
+1
A:
Sure. I've done it by subclassing System.Windows.Window and adding the capacity to show various kinds of content (images, text and controls), and then calling ShowDialog() on that Window:
public partial class MyMessageBox : Window
{
// perhaps a helper method here
public static bool? Show(String message, BitmapImage image)
{
// NOTE: Message and Image are fields created in the XAML markup
MyMessageBox msgBox = new MyMessageBox() { Message.Text = message, Image.Source = image };
return msgBox.ShowDialog();
}
}
In the XAML, something like this:
<Window>
<DockPanel>
<Image Name="Image" DockPanel.Dock="Left" />
<TextBlock Name="Message" />
</DockPanel>
</Window>
codekaizen
2010-07-03 01:50:38
didn`t work with me, in the var msgBox, Message and Image gives me errors!!
sikas
2010-07-03 02:04:24
@sikas, you must be using Visual Studio 2005. The above syntax will work with the newer C# compiler in VS2008 and later. If you're stuck with VS2005, replace the "var msgBox..." line with three lines: "MyMessageBox msgBox = new MyMessageBox();", "msgBox.Message = message;", and "msgBox.Image = image;".
Joe White
2010-07-03 05:01:27
@silkas - whoops, sorry, I'm just so accustomed to C# 3.0 now... Joe is exactly right, and I've edited the answer to reflect his suggestions.
codekaizen
2010-07-03 05:52:31
A:
RRUZ
2010-07-03 01:55:00