You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm sure there is a very good reason why it was never done in the past (and if that's still valid, please share), but what's to stop adding support for the ability to apply a Style to an Interface?
The main reason for wanting this is that I believe it would greatly reduce the amount of code needed to set styles and better enable the clear inheritance of visual styles.
For example, if I wanted to set the default FontFamily throughout an app, [at minimum] I need to apply that to the implicit styles of all controls that have a FontFamily property.
Instead, what if I could set the style on IFontElement (which has the FontFamily property). As this interface is implemented by all controls that show text, it would only be necessary to specify the desired value once. (Rather than multiple times.)
Such simplified code is quicker and easier to read, write, comprehend, and change.
Yes, this might not automatically work for any custom/3rd-party controls that show text but don't implement the interface, but the exceptions could be worked around using currently existing functionality. It may also serve as an encouragement to implement interfaces where properties are defined.
Rather than change Style.TargetType to work with interfaces, I expect it would be preferable to use a different property. Perhaps Style.TargetInterface as this would indicate that it is working differently to what already exists; would allow existing code to be unchanged; and would make validating the specified target easier.
Specifying both TargetType and TargetInterface on the same Style should not be supported and cause an error.
Alternatively a new class (InterfaceStyle?) could be used instead of Style.
Yes, I expect the way styles are resolved and applied would need to change. No, I don't know how much work that would be and so haven't factored that into thoughts about "what if?" and "why not?" doing this.
Do others think this would be useful?
Is there a reason why this would never be possible?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm sure there is a very good reason why it was never done in the past (and if that's still valid, please share), but what's to stop adding support for the ability to apply a Style to an Interface?
The main reason for wanting this is that I believe it would greatly reduce the amount of code needed to set styles and better enable the clear inheritance of visual styles.
For example, if I wanted to set the default FontFamily throughout an app, [at minimum] I need to apply that to the implicit styles of all controls that have a
FontFamily
property.Instead, what if I could set the style on
IFontElement
(which has theFontFamily
property). As this interface is implemented by all controls that show text, it would only be necessary to specify the desired value once. (Rather than multiple times.)Such simplified code is quicker and easier to read, write, comprehend, and change.
Yes, this might not automatically work for any custom/3rd-party controls that show text but don't implement the interface, but the exceptions could be worked around using currently existing functionality. It may also serve as an encouragement to implement interfaces where properties are defined.
Rather than change
Style.TargetType
to work with interfaces, I expect it would be preferable to use a different property. PerhapsStyle.TargetInterface
as this would indicate that it is working differently to what already exists; would allow existing code to be unchanged; and would make validating the specified target easier.Specifying both
TargetType
andTargetInterface
on the same Style should not be supported and cause an error.Alternatively a new class (
InterfaceStyle
?) could be used instead of Style.Yes, I expect the way styles are resolved and applied would need to change. No, I don't know how much work that would be and so haven't factored that into thoughts about "what if?" and "why not?" doing this.
Do others think this would be useful?
Is there a reason why this would never be possible?
Beta Was this translation helpful? Give feedback.
All reactions