-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Use global SystemParameters.FocusVisualStyleKey insead of per control FocusVisual style #2976
Comments
@Yoooi0 I am not sure that approach would work though (without having tested it). When you define a I believe you would still need to define a Just my thoughts, and again I may be wrong... |
The The KeyboardNavigation class in wpf just finds the style by key: And the default wpf focus visual style is defined as: In the same file you can also see the exact |
@Yoooi0 Then it makes more sense to me (since I think I understand your intention with the description now, thanks 😃 You state that
I think the problem with that is that the library itself does not ship with an App.xaml AFAIK; the demo app of course does, but that is not what you consume. Forcing that boiler-plate code onto consumers does not seem right to me. Another approach would be to put it in I think I am probably in over my head here 🤣 so I will let @Keboo decide... |
Yes that would be a breaking change (in time for 5.0.0 I guess 😛). <ResourceDictionary Source=".../Themes/MaterialDesignTheme.FocusVisual.xaml" /> Or have to define their own
I think this is already the case? I was getting the focus visual style (the wpf default one) on many unwanted controls because I didnt specify |
I would be surprised that you got any of the ones defined in MDIX since the But looking at the codebase, I agree that some cleanup could possibly be done. I am not sure I agree that using But centralizing the 2 different styles into a common place could be an option. I think the challenge with that is that we want those styles to be "statically reachable" via |
Yes I meant the default wpf style not mdix style.
When It seems like a wpf built-in solution for focus styles. We will wait for @Keboo input as im not an expert in wpf. |
@Yoooi0 Our conversation here triggered a need in me to dig deeper and do some testing on how things work. I think I got wiser, but whether it will be of much use for potentially solving the issue at hand is a different question. What I concluded was:
So, in order to define a "global" focus visual style somewhere in MDIX, we could use the Perhaps this is in fact what the issue description is all about?! But as my bullet 3 above shows, I don't think it is sufficient just to define the style under the right key, I believe we need to explicitly set it in all of the styles in order for it to have any effect. UPDATE: There is also a dotnet-campus repo which is a fork of the WPF repo. In there, there is still an open PR which references it. |
Yes was about to mention that issue 😅 I just tested mdix demo app from master branch with this at the bottom of App.xaml: <Style x:Key="{x:Static SystemParameters.FocusVisualStyleKey}" TargetType="Control">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle StrokeThickness="1" Stroke="red" SnapsToDevicePixels="true" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> And you are correct, by default it seems to not work. |
@Yoooi0 I just noticed my error, I had my solution setup to run the net472 version of the output, not the .NET7. Changing that allows me to override it correctly. However since MDIX supports older frameworks, I still think we would need to apply the style key explicitly to have the same behavior across the board. I doubt that a change like this will be backported to older frameworks. |
Doh, didnt even think to check, assumed visual studio will choose latest by default.
I think the simplest solution would be to just not specify any custom focus styles in mdix, which means all controls will use the default built-in wpf style, and since they are exactly the same anyways it wont be that big of an issue. You just wont be able to override it on anything below .net 7, but at least we would be able to override it in .net 7. |
That is definitely an option, let's see what @Keboo thinks. And Kevin, sorry for the loooong conversation with you being mentioned multiple times 😬 |
Wow lots of great discussion here (and no, I don't mind the tags 😃). First a thank you to both of you for digging into this. First a quick comment on versioning and backwards compatibility. Though this library tries to follow SemVer it is a little difficult, as SemVer intentionally does not define "backwards compatible". In C# there are two forms of backwards compatibility (binary and source). With .NET Core, and the global assembly cache (GAC) not mattering as much, I tend to not care about binary backwards compatibility (it is somewhat rare for a newer version of the library to get used without the consuming app recompiling). Source compatibility is typically how I attempt to version this library (with the exception of the So, after looking it over, I think I am fine with simply not setting any custom focus style in the library and letting controls fall back to the default WPF. This area of the UI is one that Material Design doesn't really address and leaves a lot up to platforms to decide what is best. Typically, in these situations, I favor falling back to default WPF behavior as that will likely be what is expected by consumers. It also doesn't seem to be that bad given that with the current release, it is not really possible for people to customize it with our current setup anyway. I do also really like standardizing all of the focus visual styles into a single style keyed on Sound reasonable? One final note, if you want an easy way to debug different frameworks you can select which one VS will use when you press F5. |
This was exactly what I was hit by. It was set to |
Is your feature request related to a problem? Please describe.
A bunch of control styles define a
FocusVisual
style that is used as a setter value forFocusVisualStyle
property and there is no way to customize them other than creating custom styles for each control and settingFocusVisualStyle
to your own style.Most of them are identical:
MaterialDesignInXamlToolkit/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml
Lines 17 to 30 in 2a38b2c
Only
OptionMarkFocusVisual
seems to have different Margin:MaterialDesignInXamlToolkit/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.RadioButton.xaml
Lines 13 to 25 in 2a38b2c
I think the
FocusVisualStyle
should be globally defined withSystemParameters.FocusVisualStyleKey
in App.xaml:If Margin is all that needs to be changed for some controls then maybe a
FocusVisualAssist.Margin
could be added to allow those controls to have their ownFocusVisualStyle
:The text was updated successfully, but these errors were encountered: