Apply AccentHighBrush

4 posts, 0 answers
  1. Marcello
    Marcello avatar
    70 posts
    Member since:
    Apr 2013

    Posted 28 Nov Link to this post

    Hi,

    a simple question. 

    I work with no-xaml dll's applying a theme choosed by user dinamically.

    Now, I have simple forms with caption/control list.

    When the control receive the focus I want apply to relatative caption (that is a textblock) a different foreground.

    A good ipothesys is to apply current AccentHighBrush but I don't know the current theme.

    Another idea is set a style in code-bihind for the textblock when control is focused and remove style wen focus lost.

    But, wath style I can apply to textblock?

    Other ideas?

    marc.

     

  2. Martin
    Admin
    Martin avatar
    108 posts

    Posted 01 Dec Link to this post

    Hello,

    I could suggest using an approach similar to what we are using in the implicit styles mechanism for styling our controls. I have prepared a sample project which uses several dependency properties on a user control, which are used to pass brushes or states and are set in styles targeting that user control in each of the used themes. When the theme is changed, all the resources for it should be remerged, which is the point when you could know which theme the user had chosen and the style for the custom form could be remerged as well. The framework should take care of applying the new style. Furthermore, I have created a property that is set/unset when the focus state of the form is changed by overriding the OnGotKeyboardFocus and OnLostKeyboardFocus of the form and named it IsFocusedWithin. It is used in the trigger in the style to change the HeaderForeground dependency property.

    In the project I have added the Office2016 and the VisualStudio2013 themes, but the approach is the same for any other theme(s) you might to choose to use in noXAML scenario.

    As for the brushes - there are different brushes for each of the themes which have different purposes and there is no uniform approach to the count or the naming of the palette brushes in the themes in general which stems from their core design differences.

    If you would not want to use a style targeting the custom user control, you can use a similar approach with a style for each theme targeting only the TextBlock via a DynamicResource reference and a DataTrigger in the style that binds to a custom property of the form (as proposed above) and changes the foreground.

    I hope that one of theres would be an acceptable solution for your request. If you have any other questions, please do not hesitate to contact us further.

    Regards,
    Martin
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Marcello
    Marcello avatar
    70 posts
    Member since:
    Apr 2013

    Posted 01 Dec in reply to Martin Link to this post

    Hi Martin,

    I understand your approach and yes, it works fine but it is terrible verbose.

    I prefer rather a static class linked with my ThemeManager class that set two or three paramaters (BackgroundBrush, ForegroundBrush, AccentBrush) for each theme and I can use it.

    This is also verbose and I was hoping to avoid it, bau if this is not possible...

    I think is a good idea for the future that every Telerik.Theme inherits froma ThemeBase that must define:

    - a generic BackgroundBrush

    - a good ForegroundBrush that we can use with this theme

    - a good AccentBrush that we can use with this theme

    marc

  4. Martin
    Admin
    Martin avatar
    108 posts

    Posted 06 Dec Link to this post

    Hi Marc,

    The foreground is normally named MarkerBrush and the background - MainBrush, however the accents differ from theme to theme (Accent, AccentNormal, AccentHigh/Low etc.). However, the static palette properties are implemented per class and the base class does not require them, so there is no abstract way to access them. The theme palettes are singletons and provide custom dynamic extensions for each of them, so verbose is the only way in which the framework would allow us to use that mechanism and have all the benefits of intellisence, xaml, and designer support and extraction etc. But we might consider exposing a generic mechanism for interacting with the palettes.

    Regards,
    Martin
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top