Background image in custom message box RRS feed

  • Question

  • Good day

    I created  a custom message box in my project to display some articles and questions are

    1. How can set a background image for the message box instead of the default black background

    2. How to align text to the center

    3. There are two buttons beneath the message box, how can i make these buttons open a separate message box displaying another text

    This is my code below

    CustomMessageBox cmb;
            private void Hymn_Click(object sender, System.Windows.Input.GestureEventArgs e)
                // create new Stack panel

                StackPanel sp = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Vertical };
                 //Create new label

                TextBlock tb = new TextBlock()


                    Text = "Passage I \r\n\r\n One of the interesting things to me about our space-ship is that it is a mechanical vehicle, just as is an auto-mobile. If you own a car, you realize that you must put oil and gas into it, and you must put water in the radia-tor and take care of the car as a whole. You begin to develop quite a tittle thermodynamic sense. You know that you are'either going to have to keep the machine in a good order or it is going to be in trouble and fail to function. We have not been seeing our spaceship Earth as an intergrally - designed machine which to be per-sistently successful, must be comphrehended and ser-viced in total. \r\n\r\n  Now there is one outstanding important fact regard-ing Spaceship Earth, and that is that no instruction. Our ship, in view of the infinite attention to all other details displayed by our ship. It must be taken as deliberate and purposeful that an instruction book was omitted. Lack of instruction has forced us to find out that there are two kinds of mangoes - unriped mangoes that will kill us and riped mangoes which will nourish us. And we had to find out ways of telling which-was-which mangoes before we ate it or otherwise we would die. So we were forced, because of this to devise scientific experimental procedures and to interprete effectively the significance of the experimental findings. Thus, be-cause the instruction manual was missing, we are learn-ing how we can safely survive on the planet. \r\n\r\n  Quite clearly, all living beings are utterly helpless at the moment of birth. The human child stays helpless longer than the young of any species. Apparently, it is part of the 'invention' that man is meant to be utterly helpless through certain anthropological phases. When he begins to be able to get on a little better, he is meant to discover some physical principles inherent in the universe as well as the many resources around him which will further multiply his knowledge. Designed into his Spaceship Earth's total wealth was a big safety fac-tor. This allowed man to be very ignorant for a long time until he had amassed enough experiences from which to extract progressively the system of generalized prin-ciples governing increase of energy. The designed omission of the instruction book forced man to discover retrospectively just what his most important capabili-ties are. He learned to generalize fundamental principles of universe. ",

                    TextWrapping = TextWrapping.Wrap,

                    FontSize = 25,
                    Height = 1000,



                //Create new Scroll viewer

                ScrollViewer sv = new ScrollViewer()






                // add texblock in scroll viewer

                sv.Content = tb;


                //Add the controls to stack panel



                // Create new Custom Message Box instance

                cmb = new CustomMessageBox()


                    // Set its content to our Stack Panel

                    Content = sp,


                    Opacity = 0.98,


                    // Left button of message box Button

                    LeftButtonContent = "Previous",


                    //Right button of message Box




                //Show the message box...



    Regards and reply soon

    Jayjay john

    Monday, October 13, 2014 11:02 PM


  • Hi Joakins,

    For your first question, every container XAML has a background property, you can use an ImageBrush to set this property. Code looks like.

    sp1.Background = new ImageBrush()
                    Stretch = Windows.UI.Xaml.Media.Stretch.UniformToFill,
                    ImageSource = new BitmapImage { UriSource = new Uri("ms-appx:/Assets/aaa.png") }

    For you second question, use TextAlignment property.

    tb.TextAlignment = TextAlignment.Center;

    Your third question, per my understanding, the message box will block the UI to show itself. So you cannot open another message box when it is opening.

    If you still have questions, please post more information about your scenario.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Joakins Wednesday, October 15, 2014 3:19 PM
    Tuesday, October 14, 2014 6:48 AM