Setting a Control's Visual State ... via the LayoutRoot's VSM or via C# RRS feed

  • Question

  • Greetings All,


    I'm developing an interface which needs to toggle between a Day mode and a Night mode.  I can update the majority of elements/colours simply by creating a VisualState for "DayModeActive" and one for "NightModeActive", the elements I can't modify directly via the LayoutRoot's VSM are the 'NightMode' states I have created within my control templates (e.g. buttons, TabsItems, sliders etc).  Is it possible to call/set these states via the LayoutRoot VSM?


    ... If I can't, I assume I can do it like this (via C#) on a click event ...




    foreach (var ElementName =  "OPTION_BUTTON"; "MORE_BUTTON";) // ... list a few dozen controls
                {  var controlName = ElementName;

                    var control = this.FindName(controlName) as System.Windows.Controls.Primitives.ButtonBase;
                    if (control != null)
                {VisualStateManager.GoToState(this.control, "NightMode", true);}




    ... simply listing all the controls I want to change to their 'NightMode' states and do a 'foreach' ... alas I can't get this to work either.  :(


    Any assistance much appreciated,



    Tuesday, July 20, 2010 4:00 PM