Forums

Dynamic Themes
Last Post 24 Nov 2015 04:27 PM by Andy Adshead. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Andy AdsheadUser is Offline
New Member
New Member
Posts:24


--
24 Nov 2015 11:59 AM
    Hi,
    Currently I have created an instance of the Light theme, added a custom resource named "Hello" and then I change the value of this key on a resize event (just an easy place to put some binding) however when I resize the window the dictionary itself gets updated yet the corresponding string on the screen never get updated.
    ResourceDictionary.DefaultDictionary = Light.GetThemeDictionary();
    ResourceDictionary.DefaultDictionary.Add("Hello", "hello2");
    
    SpriteFont font = Content.Load<SpriteFont>("Segoe_UI_15_Bold");
    FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(font);
    MainWindow = new MainWindow();
    viewModel = new MainWindowViewModel(MainWindow);
    MainWindow.DataContext = viewModel;
    
    graphCanvas = VisualTreeHelper.Instance.FindElementByName(MainWindow, "GraphCanvas") as Canvas;
     graphCanvas.SizeChanged += (sender, args) =>
                                                  {
                                                    MainWindow.Resources["Hello"] = "Resize Event";
                                                     // Do I need to push the change here?
                                                  };


    Is it possible to change the resource dictionary during run-time? This would allow dynamic styling and resources. Also is dictionaries the best method for localization or is there a better alternative? If so why don't dynamic resources get updated during run-time but instead behave like static resources?
    Thank you for the help,
    Andy
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:669


    --
    24 Nov 2015 01:39 PM
    Dynamic Resources are implemented to some degree. Some features are not good for performance, so it's compromise. This feature is not implemented, tho I can add that to backlog.

    I use resource dictionaries for localization. I got one per language and just swap them on the start of my game.
    Andy AdsheadUser is Offline
    New Member
    New Member
    Posts:24


    --
    24 Nov 2015 04:27 PM
    So for now I can just reload the program to change the resources. I'm glad you have added it to the backlog and it would be nice to see it working.
    Regards,
    Andy A
    You are not authorized to post a reply.