Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Dialog ignoring Accent color #3603

Closed
KKauK opened this issue Sep 12, 2019 · 11 comments
Closed

Custom Dialog ignoring Accent color #3603

KKauK opened this issue Sep 12, 2019 · 11 comments
Labels
Milestone

Comments

@KKauK
Copy link

KKauK commented Sep 12, 2019

Custom Dialog ignoring Accent color.

Steps to reproduce the behavior:

  1. Go to 'Dialog'
  2. Check "Use accent"
  3. Open Customer Dialog
  4. See error

Custom dialog should use accent color.

  • MahApps.Metro version [v2.0.0]
@timunie
Copy link
Collaborator

timunie commented Sep 12, 2019

Hello @KKauK
can you post the xaml for your custom dialog here or create a sample app? Maybe this issue is related to #3552

Happy coding
Tim

@KKauK
Copy link
Author

KKauK commented Sep 12, 2019

Hello Tim,

you can use the current MahApps.Metro.Demo.

KKauK

@KKauK KKauK closed this as completed Sep 12, 2019
@KKauK KKauK reopened this Sep 12, 2019
@KKauK
Copy link
Author

KKauK commented Sep 12, 2019

Sorry. closed by mistake!

@timunie
Copy link
Collaborator

timunie commented Sep 12, 2019

@KKauK yes, your are correct, The custom dialog ignores the Accent in the Demo. But I can easily set any Brush I want to the Background. eg. MahApps.Brushes.Accent or a Gradient as in the example image.

<Dialog:CustomDialog x:Key="CustomCloseDialogTest"
                        x:Name="CustomCloseDialogTest"
                        Title="Custom Dialog which is awaitable">
   <Dialog:CustomDialog.Background>
        <LinearGradientBrush>
            <LinearGradientBrush.GradientStops>
                <GradientStop Color="Goldenrod" Offset="0"/>
                <GradientStop Color="OrangeRed" Offset="1"/>
            </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
    </Dialog:CustomDialog.Background>

    <StackPanel>
        <TextBlock Height="30"
                    Foreground="{DynamicResource MahApps.Brushes.Accent}"
                    Text="This dialog allows arbitrary content. You have to close it yourself by clicking the close button below."
                    TextWrapping="Wrap" />
        <Button Click="CloseCustomDialog"
                Content="Close Me!"
                Style="{DynamicResource MahApps.Styles.Button.Dialogs}" />
    </StackPanel>

</Dialog:CustomDialog>

image

Is this what you are looking for?

Happy coding
Tim

@KKauK
Copy link
Author

KKauK commented Sep 12, 2019

@tim If I change the demo dialog in the MahApps.Metro.Demo I end up with this

<UserControl.Background>
    <LinearGradientBrush>
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="Goldenrod" Offset="0"/>
            <GradientStop Color="OrangeRed" Offset="1"/>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
</UserControl.Background>

....

image

Am I doing something wrong?

@KKauK
Copy link
Author

KKauK commented Sep 13, 2019

@tim Well, indeed your solution does work, but I'm trying to call customer dialog from my ViewModel. (last option in MahApps.Metro.Demo menu).

@timunie
Copy link
Collaborator

timunie commented Sep 13, 2019

Good morning @KKauK ,

In this example the CustomDialog will be created in code behind and the UserControl is loaded as the content of the dialog. So if the Background is set on the UserControl the bg will be bound to the size of the UserControl.
To archieve what you want to archieve you have to set the Background in code behind, if the CustomDialog is created in code behind.

private async void RunCustomFromVm()
{
	var customDialog = new CustomDialog() { Title = "Custom Dialog" };

	var dataContext = new CustomDialogExampleContent(instance =>
		{
			this._dialogCoordinator.HideMetroDialogAsync(this, customDialog);
			System.Diagnostics.Debug.WriteLine(instance.FirstName);
		});

	// Your usercontrol is just the content of the dialog
	customDialog.Content = new CustomDialogExample { DataContext = dataContext };

	// If you create a dialog in code behind, then you also need to implement the Background in code behind
	customDialog.Background = new LinearGradientBrush(Colors.Goldenrod, Colors.DarkOrange, 45);

	await this._dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
}

The result:
image

if you want to use a predefined resource:

// If you create a dialog in code behind, then you also need to implement the Background in code behind
customDialog.Background = (Brush)Application.Current.Resources["[The ResourceKey goes here, eg. MahApps.Brushes.Accent]"];

Happy coding
Tim

@KKauK
Copy link
Author

KKauK commented Sep 13, 2019

Good morning @tim,

that's what I was looking for. Appreciate your help!

Nevertheless wouldn't it be better if the customer dialog would also apply the "Accent" if the option "Use accent" is set?

Thank you
Kkauk

@timunie
Copy link
Collaborator

timunie commented Sep 13, 2019

@KKauK I don't know if this is a good idea, as the Foreground also has to change for some accents. I think there are so many possibilities, that you cannot implement this easily.

Happy coding
Tim

@KKauK
Copy link
Author

KKauK commented Sep 13, 2019

@tim Okay, might be true.

Thanks again
KKauK

@punker76 punker76 added the Bug label Sep 15, 2019
@punker76 punker76 added this to the 2.0.0 milestone Sep 15, 2019
punker76 added a commit that referenced this issue Sep 15, 2019
The main sample doesn't use the accent color change for all samples.
@punker76
Copy link
Member

@KKauK this has now been fixed, and it will be released in the next version of MahApps.Metro v2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants