I have been searching google but I did not find how to display a message in C# win store app. Actually I have been developing a app in which user will input. I have built rgex. When a text box is empty & user click on validate button it would display a message to prompt the user to first input data then he has to click on vaslidate.

Dani AI

Generated

Short answer: for a quick modal prompt use Windows.UI.Popups.MessageDialog (what pointed to). For modern XAML/Windows 10+ apps prefer ContentDialog or an in-app overlay like suggested — Microsoft now recommends ContentDialog over the older MessageDialog. (learn.microsoft.com)

Example — MessageDialog (WinRT / older Windows Store code):

private async void ValidateButton_Click(object sender, RoutedEventArgs e)
{
    if (string.IsNullOrWhiteSpace(MyTextBox.Text))
    {
        var dialog = new Windows.UI.Popups.MessageDialog("Please enter a value.", "Input required");
        await dialog.ShowAsync();
        return;
    }

    // proceed with validation...
}

MessageDialog lives in Windows.UI.Popups and is fine for small, blocking alerts or when porting older Store apps — but it has threading/marshaling caveats and Microsoft recommends ContentDialog for new XAML apps. (learn.microsoft.com)

Recommended — ContentDialog (UWP / WinUI):

private async void ValidateButton_Click(object sender, RoutedEventArgs e)
{
    if (string.IsNullOrWhiteSpace(MyTextBox.Text))
    {
        var dlg = new ContentDialog
        {
            Title = "Missing input",
            Content = "Please enter a value and tap Validate.",
            CloseButtonText = "OK"
        };

        // If required by your host (WinUI/WinApp SDK), set XamlRoot:
        // dlg.XamlRoot = this.XamlRoot;

        await dlg.ShowAsync();
        return;
    }
}

ContentDialog is the current recommended control; remember there can only be one ContentDialog per window and you may need to set XamlRoot when showing a dialog from certain hosts. (learn.microsoft.com)

UX note: for a single empty-textbox check, prefer inline validation (highlight the field, show a small TextBlock error) instead of modal dialogs — dialogs should be reserved for important blocking situations. This keeps validation fast and less disruptive. (learn.microsoft.com)

Recommended Answers

All 2 Replies

Microsoft recommends that you do not create "dialog boxes" as we do in "normal" windows programming. They have some specifics about what a dialog box should look like in Modern apps.

I believe there might be some built in ones in Calisto, however, I typically use a very simple (although configurable) UserControl with a solid color (usually the blue windows uses) as the main background to the dialog with opacity set on the upper and lower borders.

For example:

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="400"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Rectangle Grid.Row="0" Grid.RowSpan="3" Fill="Black" Opacity=".5" />
        <Grid Grid.Row="1" Background="DarkSlateGray">
            <TextBlock TextWrapping="Wrap"  x:Name="txtText" Margin="25,100,25,0" VerticalAlignment="Top"/>
            <Button x:Name="btnOk" Height="80"  Margin="50,50,50,50" Click="btnOk_Click" VerticalAlignment="Bottom">Ok</Button>
        </Grid>
    </Grid>

Hope this helps.

Mark A. Malo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.