c# - How to Show Image in CustomMessageBox -


I need to display an image as the contents of the CustomMessageBox. I have tried to set it up, still no image has been displayed, but everything else looks fine.

  image image = new image (); Bitmap image BMP = new bitmap image (new urie ("/ assets / image page", uricind .relative)); Image.Source = bmp as ImageSource; CustomMessageBox Message Box = New CustomMessageBox () {Caption = "\ n" + "Caption", Message = "\ n" + "Message +." \ N ", LeftButtonContent =" left button ", content = image}; messageBox.Dismissed + = (S1, E1) => {switch (e1.Result) {case CustomMessageBoxResult.LeftButton: MessageBox.Show (" left Button "); break; Case CustomMessageBoxResult.None: MessageBox.Show (" None "); Break: Default: MessageBox.Show (" default "); break;}}; messagebox.Show ();  < / Pre>  

You can add a custom UI as a content of a custom message box. I did this. This is a code from my project. It has an image and a text box that is a stackpane To create a method UI.

  Private StackPanel CreateUI (String ImagePath, String Username) {StackPanel userStack = New StackPanel () {Orientation = System.Windows.Controls.Orientation.Horizontal , HorizontalAlignment = System.Windows.HorizontalAlignment.Left, margin = new thickness (3, 6, 24, 0, 0)}; image profilePic = new image () {source = new BitmapImage (New Uri (ImagePath, UriKind.Absolute) , Name = "imgProfile", height = 100, width = 100, margin = new thickness (0, 0, 6, 0)}; TextBlock username = new TextBlock () {text = username, name = "txblkUserName", foreground = new SolidColorBrush (Colors.White), FONTSIZE = 32, margin = new thickness (0, 12, 0, 0)}; UserStack.Children.Add (profilePic); UserStack.Children.Add (username); User stock return; }   

And here's how I added it to CustomMessageBox.

  CustomMessageBox MsgBox = New CustomMessageBox () {Caption = "Your Caption", Content = This.CreateUI (profilePic, User Name), Message = "Your Message", LeftButtonContent = "Left Button Content "}; MsgBox.Show ();   

It works perfectly Hope it will help :)

** Edit: If your image is inside your project, then Uricund Should be turned into a relative.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -