tags:

views:

169

answers:

2

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
didn`t work with me, in the var msgBox, Message and Image gives me errors!!
sikas
@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
@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
A: 

@sikas, check theses links

alt text

RRUZ