AvaloniaUtils / DialogHost.Avalonia

AvaloniaUI control that provides a simple way to display a dialog with information or prompt the user when information is needed
MIT License
228 stars 15 forks source link

Empty dialog content's visuals #1

Closed Gigas002 closed 2 years ago

Gigas002 commented 3 years ago

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.

SKProCH commented 2 years ago

Sorry for the long answer.

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

SKProCH commented 2 years ago

Seems like i can't reproduce this. I copied the code and repeated all the steps, but everything works for me. Анимация Here is my project: MyApp.zip

Gigas002 commented 2 years ago

@SKProCH Thank you for your answer, and sorry, that I didn't provide full reproducable code sample. Seems like this problem only occurs when setting <FluentTheme Mode="Dark"/> in App.axaml.

SKProCH commented 2 years ago

Seems like there a white text on white background. If i change dialog content background color to Black i get this: image

Gigas002 commented 2 years ago

Ah, that's how it is. Thought it would automatically catch up with the selected theme (at least user control itself seems to find it correctly). Is this an expected behaviour and I should set the background by myself, or is it a bug?

SKProCH commented 2 years ago

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

SKProCH commented 2 years ago

It fixed in 0.2.1 version