Ticket T579152
Visible to All Users

OBSOLETE - How to show Color Swatches for the Bezier skin and persist the user choice in XAF WinForms apps

created 7 years ago

[DevExpress Support Team: CLONED FROM T578454: SVG Skins and Palettes – FAQ]
In the WinForms demo there's a "Color Swatches" button, how do I add it to XAF and save the selection for the next login of the user?

Show previous comments (5)
J J
Juan Antonio Trujillo Montenegro 7 years ago

    @Yauhen setting the action's category to Windows as shown in the code above does the trick. See attached file ;-)

    PS. At first I tried with the other categories and didn't see the action at any place until I tried with each one and discovered the 'Windows' category did the trick, it's weird name, one would expect to find it under 'View' or 'Appearances'…

    SM SM
    Santiago Moscoso 7 years ago

      @Juan Antonio,  the ChooseSkin action is on the 'Appearance' category.

      J J
      Juan Antonio Trujillo Montenegro 7 years ago

        @Santiago That's correct, however, when I set the new ColorSwatchAction to such category is not shown in any place; nonetheless, setting it in Windows category shows next to the ChooseSkin action as shown in my attached image.

        Answers approved by DevExpress Support

        created 7 years ago (modified 6 years ago)

        With v18.2, the Light Style Main Form Template and Light Style Main Ribbon Form Template contain the built-in palette selector for the Bezier skin.

        To use these templates, set the WinApplication.UseLightStyle property to True. To enable this feature in an existing application with custom templates, refer to the How to migrate a WinForms application to use the Light Style article.
        -------------------------------------------------------------------------------------

        For other Main Form templates and previous versions, use the following solution.

        To provide the end user with the capability to select a color palette and persist the choice in the application model, you can add the following controller into the YourSolutionName.Module.Win project:

        C#
        using System.ComponentModel; using System.Linq; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Win; using DevExpress.ExpressApp.Win.SystemModule; using DevExpress.LookAndFeel; using DevExpress.Skins; namespace MainDemo.Module.Win.Controllers { public class SvgSkinController : WindowController, IModelExtender { private SimpleAction showPaletteAction; private ChooseSkinController chooseSkinController; public SvgSkinController() { TargetWindowType = WindowType.Main; this.showPaletteAction = new SimpleAction(this, "ShowPalette", "Panels"); this.showPaletteAction.Execute += ShowPaletteAction_Execute; this.showPaletteAction.ImageName = "Action_ChooseSkin"; } protected override void OnFrameAssigned() { base.OnFrameAssigned(); chooseSkinController = Frame.GetController<ChooseSkinController>(); if (chooseSkinController != null) { chooseSkinController.ChooseSkinAction.ExecuteCompleted += ChooseSkinAction_ExecuteCompleted; } } private void ChooseSkinAction_ExecuteCompleted(object sender, ActionBaseEventArgs e) { RestorePalette(Application); UpdateActionActivity(showPaletteAction); } protected override void Dispose(bool disposing) { base.Dispose(disposing); if(disposing && chooseSkinController != null) { chooseSkinController.ChooseSkinAction.ExecuteCompleted -= ChooseSkinAction_ExecuteCompleted; } } public static void RestorePalette(XafApplication application) { var model = (IModelApplicationOptionsSkinSvg)application.Model.Options; if(model.Palette == null) return; var skin = CommonSkins.GetSkin(UserLookAndFeel.Default); DevExpress.Utils.Svg.SvgPalette palette = skin.CustomSvgPalettes[model.Palette]; if(palette != null) { skin.SvgPalettes[Skin.DefaultSkinPaletteName].SetCustomPalette(palette); LookAndFeelHelper.ForceDefaultLookAndFeelChanged(); } } public static void SavePalette(XafApplication application) { var model = (IModelApplicationOptionsSkinSvg)application.Model.Options; model.Palette = UserLookAndFeel.Default.ActiveSvgPaletteName; } private void ShowPaletteAction_Execute(object sender, SimpleActionExecuteEventArgs e) { var form = ((WinWindow)Window).Form; using(var dialog = new DevExpress.Customization.SvgSkinPaletteSelector(form)) { dialog.ShowDialog(); SavePalette(Application); } } protected override void UpdateActionActivity(ActionBase action) { base.UpdateActionActivity(action); var isSvgSkin = UserLookAndFeel.Default.ActiveStyle == ActiveLookAndFeelStyle.Skin && UserLookAndFeel.Default.ActiveSkinName == SkinStyle.Bezier; action.Active["Svg"] = isSvgSkin; } public void ExtendModelInterfaces(ModelInterfaceExtenders extenders) { extenders.Add<IModelApplicationOptionsSkin, IModelApplicationOptionsSkinSvg>(); } } public interface IModelApplicationOptionsSkinSvg { [Category("Appearance")] string Palette { get; set; } } }
        Visual Basic
        Option Infer On Imports System.ComponentModel Imports System.Linq Imports DevExpress.ExpressApp Imports DevExpress.ExpressApp.Actions Imports DevExpress.ExpressApp.Model Imports DevExpress.ExpressApp.Win Imports DevExpress.ExpressApp.Win.SystemModule Imports DevExpress.LookAndFeel Imports DevExpress.Skins Namespace MainDemo.Module.Win.Controllers Public Class SvgSkinController Inherits WindowController Implements IModelExtender Private showPaletteAction As SimpleAction Private chooseSkinController As ChooseSkinController Public Sub New() TargetWindowType = WindowType.Main Me.showPaletteAction = New SimpleAction(Me, "ShowPalette", "Panels") Me.showPaletteAction.ImageName = "Action_ChooseSkin" AddHandler Me.showPaletteAction.Execute, AddressOf ShowPaletteAction_Execute End Sub Protected Overrides Sub OnFrameAssigned() MyBase.OnFrameAssigned() chooseSkinController = Frame.GetController(Of ChooseSkinController)() If chooseSkinController IsNot Nothing Then AddHandler chooseSkinController.ChooseSkinAction.ExecuteCompleted, AddressOf ChooseSkinAction_ExecuteCompleted End If End Sub Private Sub ChooseSkinAction_ExecuteCompleted(ByVal sender As Object, ByVal e As ActionBaseEventArgs) RestorePalette(Application) UpdateActionActivity(showPaletteAction) End Sub Protected Overrides Sub Dispose(ByVal disposing As Boolean) MyBase.Dispose(disposing) If disposing AndAlso chooseSkinController IsNot Nothing Then RemoveHandler chooseSkinController.ChooseSkinAction.ExecuteCompleted, AddressOf ChooseSkinAction_ExecuteCompleted End If End Sub Public Shared Sub RestorePalette(ByVal application As XafApplication) Dim model = DirectCast(application.Model.Options, IModelApplicationOptionsSkinSvg) If model.Palette Is Nothing Then Return End If Dim skin = CommonSkins.GetSkin(UserLookAndFeel.Default) Dim palette As DevExpress.Utils.Svg.SvgPalette = skin.CustomSvgPalettes(model.Palette) If palette IsNot Nothing Then skin.SvgPalettes(Skin.DefaultSkinPaletteName).SetCustomPalette(palette) LookAndFeelHelper.ForceDefaultLookAndFeelChanged() End If End Sub Public Shared Sub SavePalette(ByVal application As XafApplication) Dim model = DirectCast(application.Model.Options, IModelApplicationOptionsSkinSvg) model.Palette = UserLookAndFeel.Default.ActiveSvgPaletteName End Sub Private Sub ShowPaletteAction_Execute(ByVal sender As Object, ByVal e As SimpleActionExecuteEventArgs) Dim form = CType(Window, WinWindow).Form Using dialog = New DevExpress.Customization.SvgSkinPaletteSelector(form) dialog.ShowDialog() SavePalette(Application) End Using End Sub Protected Overrides Sub UpdateActionActivity(ByVal action As ActionBase) MyBase.UpdateActionActivity(action) Dim isSvgSkin = UserLookAndFeel.Default.ActiveStyle = ActiveLookAndFeelStyle.Skin AndAlso UserLookAndFeel.Default.ActiveSkinName = SkinStyle.Bezier action.Active("Svg") = isSvgSkin End Sub Public Sub ExtendModelInterfaces(ByVal extenders As ModelInterfaceExtenders) Implements IModelExtender.ExtendModelInterfaces extenders.Add(Of IModelApplicationOptionsSkin, IModelApplicationOptionsSkinSvg)() End Sub End Class Public Interface IModelApplicationOptionsSkinSvg <Category("Appearance")> Property Palette() As String End Interface End Namespace

        The main code is borrowed from the SVG Skins and Palettes – FAQ article for our WinForms components and is executed in the UI using the ShowPalette SimpleAction, which is activeonly when the Bezier skin is selected or the ChooseSkinController's Action is executed:

        This action invokes the customization dialog for further skin tuning:

        To save the palette user choice, the Options node in the Model Editor is extended as per the Concepts > Application Model > Extend and Customize the Application Model in Code  article:

        The ShowPalette action is assigned to the "Panels" category shown in the same sub-menu or Ribbon page as the ChooseSkin action. The "Appearance" category in existing templates cannot show additional actions because there's no action container. To place this action at a different location, you can either follow the UI Customization > Place an Action in a Different Location  approach or create a custom main window template with an additional action container as described in the How to: Create a Custom WinForms Ribbon Template and How to: Create a Custom WinForms Standard Template articles.

          Comments (1)
          DevExpress Support Team 7 years ago

            I'd like to inform you about our progress in supporting SVG images and ask for your feedback. Please check out the WinForms SVG Images Support - v18.1 Preview article. We would greatly appreciate it if you test this functionality, report your comments and answer our questions. Also, see the XAF - Access v18.1 Features Today for Early Testing blog post for other new coming features.

            Thank you for your time and cooperation.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.