microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

Question: How to do lightweight-styling per style? #4825

Closed HppZ closed 3 years ago

HppZ commented 3 years ago

https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/xaml-styles#lightweight-styling image

StephenLPeters commented 3 years ago

Style does not have a Resources property. If you are a control author that wants to use the light weight style model for the controls in your library the method to do this is to have your control templates reference well known resources by name using {StaticResource} or {ThemeResource} and then publish the default value for those resources along with your styles. If you are an app author you can interact with the winui2 light weight styling by providing overrides to the well known named resources our templates use. We recommend you do this in your application.Resources within the merged dictionaries of your XamlControlsResources.

....
HppZ commented 3 years ago

I am an app author, I want to override the well known named resources at Style level, not app level or control level. I need ButtonStyle1, ButtonStyle2, ButtonStyle3 with different overrides. How to do that?

mdtauk commented 3 years ago

I am an app author, I want to override the well known named resources at Style level, not app level or control level. I need ButtonStyle1, ButtonStyle2, ButtonStyle3 with different overrides. How to do that?

Can you use BasedOn to reference an existing Style?

HppZ commented 3 years ago

I am an app author, I want to override the well known named resources at Style level, not app level or control level. I need ButtonStyle1, ButtonStyle2, ButtonStyle3 with different overrides. How to do that?

Can you use BasedOn to reference an existing Style?

but how to override Brushs(ButtonBackgroundPointerOver ...) per Style(ButtonStyl1, ButtonStyl2 ...)?

mdtauk commented 3 years ago

I am an app author, I want to override the well known named resources at Style level, not app level or control level. I need ButtonStyle1, ButtonStyle2, ButtonStyle3 with different overrides. How to do that?

Can you use BasedOn to reference an existing Style?

but how to override Brushs(ButtonBackgroundPointerOver ...) per Style(ButtonStyl1, ButtonStyl2 ...)?

I don't think you can per Style. You would have to override the style in a page or panel's resources.

HppZ commented 3 years ago

I don't think you can per Style. You would have to override the style in a page or panel's resources.

I think it is not flexible so I ask for help here, I thought there is a better way.

marcelwgn commented 3 years ago

I'm afraid there isn't much you can do or this. Styles don't allow overriding the Resources property so you would have to override the resources on every control.

mdtauk commented 3 years ago

I'm afraid there isn't much you can do or this. Styles don't allow overriding the Resources property so you would have to override the resources on every control.

Having said that, Style.Resources sounds like it could be a useful feature for "bundling" up all the light-weight styles associated with a control and it's template.

marcelwgn commented 3 years ago

I'm afraid there isn't much you can do or this. Styles don't allow overriding the Resources property so you would have to override the resources on every control.

Having said that, Style.Resources sounds like it could be a useful feature for "bundling" up all the light-weight styles associated with a control and it's template.

Yes there should be an there already is a proposal/discussion for this: https://github.com/microsoft/microsoft-ui-xaml/issues/3939

mdtauk commented 3 years ago

I'm afraid there isn't much you can do or this. Styles don't allow overriding the Resources property so you would have to override the resources on every control.

Having said that, Style.Resources sounds like it could be a useful feature for "bundling" up all the light-weight styles associated with a control and it's template.

Yes there should be an there already is a proposal/discussion for this: #3939

I do remember this being proposed, and I did comment on the proposal - but I didn't connect the two weirdly.

StephenLPeters commented 3 years ago

Yes, today the resource system does not have a notion of resources associated with a style. I do think this could be a valuable addition to the system though.