We are working on a rather sophisticated Silverlight 3 RIA interface for our back office. Part of the functionality of this is that the user can select themes. We use Telerik themes, and this requires us to apply theme selection during App_Init.
So we probably have a user interface for choosing themes, but then we need to restart the application to apply the themes.
Obviously, this will be easy in the browser - we just go to HtmlPage and add JavaScript.
But what about a browser application? Another requirement for this is that OOB has detected and downloaded an updated version of the application.
(Search around this and no one seems to address this issue)
UPDATE 1 (thanks Valerie)
We applied the Valeri code, but there are problems. We believe that a topic can only be set once. We have:
- Moved XAML to a new UserControl (LayoutMockup)
- Install RootVisual in the grid and add MainPage to the Grid in App_Init
On our MainPage we have (class1 is our creatively titled theme):
public MainPage() { InitializeComponent(); this.InitializeUI(); Class1 customTheme = new Class1(); customTheme.Source = new Uri("/Migturbo_Spring;Component/Themes/MyGeneric.xaml", UriKind.Relative); ChangeTheme(customTheme); }
as well as the following code:
public void ChangeTheme(Theme theme) { StyleManager.ApplicationTheme = theme; // FAILS HERE 2ND TIME this.LayoutRoot.Children.Clear(); this.InitializeUI(); } private void InitializeUI() { this.LayoutRoot.Children.Add(new LayoutMockup()); }
At the first start it works. The theme "Spring / Class1" is correctly applied. The second time (initiated by the mock button in the user interface), the ChangeTheme () method is called with a known working theme, we get an exception:
Correction System.Exception was not handled by the user Code Message = " Error HRESULT E_FAIL was returned from calling the COM component. " StackTrace: in MS.Internal.XcpImports.CheckHResult (UInt32 h) in MS.Internal.XcpImports.SetValue (INativeCoreTypeWrapper obj, property DependencyProperty, String s) ...... etc.
We took the path of restarting the application, as opposed to switching themes, because we read somewhere that this is not possible. But we are not familiar with Silverlight and are happy to be educated. :)
Any approach would be great.