Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Style not applied for my Custom button #17545

Closed
samyraj42 opened this issue Nov 18, 2024 · 2 comments
Closed

Style not applied for my Custom button #17545

samyraj42 opened this issue Nov 18, 2024 · 2 comments
Labels
by-design The behavior reported in the issue is actually correct.

Comments

@samyraj42
Copy link

samyraj42 commented Nov 18, 2024

Describe the bug

I have written code for my custom button. I have created a style for that, providing a red background color.
But that style was not applied to my custom button

To Reproduce

Step 1:

internal class CustomButton : Button
{
public CustomButton()
{

}


protected override Type StyleKeyOverride => typeof(Button);

}

Step2:

<Style Selector="local|CustomButton"> </Style>

Setp3:
<local:CustomButton
Width="150" Height="75" />

Expected behavior

No response

Avalonia version

11.1.0

OS

Windows

Additional context

No response

@samyraj42 samyraj42 added the bug label Nov 18, 2024
@timunie
Copy link
Contributor

timunie commented Nov 18, 2024

Why do you do a stylekeyoverride if you want to target your custom button? That's wrong usage here.

In case you wanted to base on button style, you need to use ControlTheme with BasedOn set accordingly.

@maxkatz6 maxkatz6 added by-design The behavior reported in the issue is actually correct. and removed bug labels Nov 18, 2024
@maxkatz6
Copy link
Member

Yes, by using StyleKeyOverride you told styling subsystem, that it should use "Button" as a style key.
Which is why "local|CustomButton" is not matching anymore.

@AvaloniaUI AvaloniaUI locked and limited conversation to collaborators Nov 18, 2024
@maxkatz6 maxkatz6 converted this issue into discussion #17546 Nov 18, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
by-design The behavior reported in the issue is actually correct.
Projects
None yet
Development

No branches or pull requests

3 participants