2

I want to show Right to Left MessageDialog. but it seems that such option does not exist.

I saw a question like this (How to center Popup in Metro style app in c#), but i think that RTL is a different issue.

is the only solution is to write my own "RTL Popup" ? if so, how ?

thank you in advance.

I've tried using this code: RTL Message code

but the result is NOT RTL: result - not RTL

Community
  • 1
  • 1
itsho
  • 4,640
  • 3
  • 46
  • 68

3 Answers3

4

Since the MessageDialog class is sealed, and there is currently no way to set a property to change the direction to rtl, your best option would be to create your own. One way to do this would be to set a Grid as the last item on a page, with Visibility set to Collapsed and then make it Visible when needed. One way to center it would be like this:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Border Grid.RowSpan="3" Background="Gray" Opacity="0.3"/> <!-- this locks the controls behind-->
    <Border HorizontalAlignment="Stretch" Background="White" Grid.Row="1" Height="300">
        <TextBlock Text="Test" HorizontalAlignment="Center" Width="300"/>
    </Border>
</Grid>

This will vertically center your content, horizontally center it and prevent the user from interacting with any background content until it is Collapsed again.

N_A
  • 19,799
  • 4
  • 52
  • 98
  • 1
    Ok, that will cover the UI part, but what about ShowAsync()? meaning - where will that part be located in? which type of Control? – itsho Jun 14 '14 at 20:24
  • 1
    Ah, you're wanting a layout control? – N_A Jun 15 '14 at 00:31
  • 1
    what other option do I have? – itsho Jun 15 '14 at 06:38
  • 1
    @itsho It appears there are some app level settings I didn't see before which might achieve what you're looking for: http://msdn.microsoft.com/en-us/library/windows/apps/hh967758.aspx The default language can determine whether or not the UI is flipped to right-to-left. – N_A Jun 15 '14 at 20:11
  • 1
    1. I haven't accepted your answer since it is not an actual `Dialog`. 2. So basically, you're saying that it is impossible to achieve without changing windows language ? – itsho Jun 16 '14 at 07:02
  • 1. As far as I can tell there is no way to create a custom `Dialog`. You're stuck with either the existing dialog or something like what I put above (which can be visually indistinguishable from a dialog even if the api is different). 2. I was suggesting you try the application level language settings, not the system level settings. The above link states how to set the app-level language default. – N_A Jun 16 '14 at 13:56
1

I don't know any C#, however maybe you could override the messageDialog.OnPaint method. I did this in VB to get the different colored text on a button when enabled was set to false.

Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
    If MyBase.Enabled Then
        If Me.Text = "" Then
            MyBase.OnPaint(pevent)
            Dim sf As SizeF = pevent.Graphics.MeasureString("Login", Me.Font, Me.Width)
            Dim ThePoint As New Point((Me.Width / 2) - (sf.Width / 2), (Me.Height / 2) - (sf.Height / 2))
            pevent.Graphics.DrawString("Login", Me.Font, Brushes.Black, ThePoint)
        Else
            MyBase.OnPaint(pevent)
        End If

    Else
        Me.Text = ""
        MyBase.OnPaint(pevent)
        Dim sf As SizeF = pevent.Graphics.MeasureString("Not Ready...", Me.Font, Me.Width)
        Dim ThePoint As New Point((Me.Width / 2) - (sf.Width / 2), (Me.Height / 2) - (sf.Height / 2))
        pevent.Graphics.DrawString("Not Ready...", Me.Font, Brushes.Red, ThePoint)
    End If

End Sub
-2

you can use below Message Dialog in ur method.

var messageDialog = new MessageDialog(" You Can Show Message Here");
                messageDialog.Title = "Alert";
                // Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
                messageDialog.Commands.Add(new UICommand(
                    "OK",
                    new UICommandInvokedHandler(this.CommandInvokedHandlerAddPics)));

                messageDialog.Commands.Add(new UICommand(
                    "No",
                    new UICommandInvokedHandler(this.CommandInvokedHandlerback)));

                // Set the command that will be invoked by default
                messageDialog.DefaultCommandIndex = 0;

                // Set the command to be invoked when escape is pressed
                messageDialog.CancelCommandIndex = 1;

                // Show the message dialog
                await messageDialog.ShowAsync();

and method for OK or No button

private void CommandInvokedHandlerAddPics(IUICommand command)
    {
        if (command.Label.Equals("OK"))
        {

        }
        else if (command.Label.Equals("No"))
        {

        }
    }
Sajid
  • 320
  • 3
  • 20