question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty dialog content's visuals

See original GitHub issue

I’ve written a simple program with avalonia’s mvvm template. Here’s my MainWindowView.xaml code:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:DialogHostTest.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:dialogHost="clr-namespace:DialogHost;assembly=DialogHost.Avalonia"
        mc:Ignorable="d"
        Width="300"
        Height="200"
        x:Class="DialogHostTest.Views.MainWindow"
        Icon="/Assets/avalonia-logo.ico"
        Title="DialogHostTest">

    <Design.DataContext>
        <vm:MainWindowViewModel/>
    </Design.DataContext>

  <dialogHost:DialogHost Identifier="{Binding DialogHostId}">
    <Button VerticalAlignment="Stretch"
            HorizontalAlignment="Stretch"
            VerticalContentAlignment="Center"
            HorizontalContentAlignment="Center"
      Content="Show dialog" Command="{Binding ShowDialogAsync}"/>
    
  </dialogHost:DialogHost>

</Window>

And here’s MainViewModel’s code:

using System.Threading.Tasks;

namespace DialogHostTest.ViewModels
{
    public class MainWindowViewModel : ViewModelBase
    {
        public static string DialogHostId => "MainDialogHost";

        public async Task ShowDialogAsync()
        {
            var result = await MessageBoxViewModel.ShowAsync("Test message!", DialogHostId);
        }
    }
}

I want to show message box on this button’s click, so I wrote a simple UserControl and ViewModel for it.

View’s code:

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="DialogHostTest.Views.MessageBoxView">

  <Grid RowDefinitions="*,10,*"
        ColumnDefinitions="*,10,*">
    <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
               Text="{Binding Message}"/>
    <Button Grid.Row="2" Grid.Column="0"
            Content="OK"
            Command="{Binding OkButton}"/>
    <Button Grid.Row="2" Grid.Column="2"
            Content="Cancel"
            Command="{Binding CancelButton}"/>
  </Grid>

</UserControl>

ViewModel’s code:

using System.Threading.Tasks;
using ReactiveUI;
using DialogHostTest.Enums;

namespace DialogHostTest.ViewModels
{
    public class MessageBoxViewModel : ViewModelBase
    {
        private string _message;

        public string Message 
        {
            get => _message;
            set => this.RaiseAndSetIfChanged(ref _message, value);
        }

        public DialogResult DialogResult { get; set; }

        public MessageBoxViewModel(string message)
        {
            Message = message;
        }

        public void OkButton()
        {
            DialogResult = DialogResult.OK;

            CloseDialog(MainWindowViewModel.DialogHostId);
        }

        public void CancelButton()
        {
            DialogResult = DialogResult.Cancel;

            CloseDialog(MainWindowViewModel.DialogHostId);
        }

        public void CloseDialog(string dialogHostId)
        {
            DialogHost.DialogHost.Close(dialogHostId, DialogResult);
        }
    
        public static async Task<DialogResult> ShowAsync(string message, string dialogHostId)
        {
            var res = await DialogHost.DialogHost.Show(new MessageBoxViewModel(message), dialogHostId);

            return (DialogResult)res;
        }
    }
}

But when I click on the button, I can’t see the desired UserControl:

What I see

That’s how it looks in VS’s designer:

How it looks in VS's designer

Though I must say, that when I click on areas, where buttons should be, the dialog closes successfully, and I receive desired DialogResult.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
SKProCHcommented, Jul 14, 2021

I think this is a bug and I’m writing a fix right now. But in general, yes, you can fix it yourself.

1reaction
SKProCHcommented, Jul 14, 2021

Sorry for the long answer.

I will try to take the time and fix it soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty toolbox when editing a dialog
Sometimes closing the dialog editor (i.e. closing all resource tabs), closing and restarting Visual Studio will repopulate the toolbox, ...
Read more >
Properties page for MFC dialog include file shows empty in ...
Solved! I'll answer my own question for reference. I have Visual Assist installed, and the other day it offered me to disable Visual...
Read more >
Problems with Blank Dialog boxes?
When I want to close a document but not do a Save As, the dialog box is supposed to come up to ask...
Read more >
Dialogs
A dialog is a type of modal window that appears in front of app content to provide critical information or ask for a...
Read more >
Modal Dialog Example | APG | WAI
Focus and accessible descriptions are set based on the content of each dialog ... The dialog has a visual border, so creating a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found