Welcome to the Xceed Community | Help
Community Search  
More Search Options

Adding Dictionaries to Application

Sort Posts: Previous Next
  •  06-15-2012, 9:00 AM Post no. 32258

    Adding Dictionaries to Application

    Hello,

    I am currently attempting to switch the program I am working on to use Xceed themes. I seem to be having some issues with adding the themes to the resources. Based on which theme is currently selected I add the ResourceDictionary of that theme to the application's MergedDictionaries using the following code

              Xceed.Wpf.Themes.LiveExplorer.LiveExplorerResourceDictionary myDictionary = new    Xceed.Wpf.Themes.LiveExplorer.LiveExplorerResourceDictionary();
              myDictionary.LicenseKey = "xxxx-xxxx-xxxx-xxxx";
              Application.Current.Resources.MergedDictionaries.Insert(0, myDictionary);

    For the most part this works in that the controls and most of the application uses the selected theme. But the Background of the Application does not change. I had read that you need to explicitly set the background of the window so I have the following line in my window xaml

               Background="{Binding {StaticResource ApplicationBackgroundBrush}}"

    But this throws an error saying it cannot find resource named 'ApplicationBackgroundBrush'. So I tried explicitly adding it to the resources by writing

               Application.Current.Resources.Add("ApplicationBackgroundBrush",   Xceed.Wpf.Themes.LiveExplorer.LiveExplorerResources.ApplicationBackgroundBrush);

    under the first code section. But this gives an error saying it already exists. Do you have any ideas on what is going on?
  •  06-16-2012, 12:44 PM Post no. 32262 in reply to 32258

    Re: Adding Dictionaries to Application

    Hi anuka,

    If you just want to set the Background property of the Window, this can be easily achieve by setting Background property in XAML without Binding. There is no Binding required and you can just do the following:

    XAML

    --------------

    <Window x:Class="TestProject.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:xcpt="http://schemas.xceed.com/wpf/xaml/themes"
            Title="MainWindow" Height="350" Width="525"
            Background="{x:Static xcpt:LiveExplorerResources.ApplicationBackgroundBrush}">

    --------------

    This XAML code was also posted on the online documentation that is available to all developers for free here. You can access the whole online documentation with the table of contents here. Moreover, you can check the list of documentation resources that we provide to the public to view and use them all here.

    I hope this helps!


    Marc

    Developer in Technical Support
    Xceed - Multi-talented components - http://xceed.com
  •  06-18-2012, 8:10 AM Post no. 32264 in reply to 32262

    Re: Adding Dictionaries to Application

    Thank you for the reply Marc.

    The code you gave would not work because that code only sets the background to one specific theme's background. We want the user to be able to switch between themes dynamically and without having to close and reopen the application. We have a dropdown list of the different themes the user can choose from. Currently, when the users choose a different theme the controls switch, but it seems like everything that is an element of the window or is put directly into the window does not change. Such as the background and the tabs that are defined in the window xaml (whereas the content inside of the tabs changes dynamically). But if we close and reopen the application everything changes to the correct theme.
  •  06-18-2012, 9:13 PM Post no. 32266 in reply to 32264

    Re: Adding Dictionaries to Application

    Hi anuka,

    If you want the user the choose the background, I would suggest having a style for each background theme you want to apply. For example

    XAML

    -------------

    <Style x:Key="style1" TargetType="{x:Type Window}">
                    <Setter Property="Background" Value="{x:Static xcpt:LiveExplorerResources.ApplicationBackgroundBrush}" />
                    <Setter Property="FontSize" Value="16" />
                </Style>

                <Style x:Key="style2" TargetType="{x:Type Window}">
                    <Setter Property="Background" Value="Blue" />
                    <Setter Property="ResizeMode" Value="NoResize" />
                    <Setter Property="ShowInTaskbar" Value="False" />
                </Style>

    -------------

    Then, in code behind, you can simply choose which style you want to apply based on the user. For example:

    C#

    -------------

    private void btnTest_Click(object sender, RoutedEventArgs e)
            {
                isTest = !isTest;

                if (isTest)
                    this.Style = (Style) this.Resources["style1"];
                else
                    this.Style = (Style) this.Resources["style2"];
            }

    -------------


    Marc

    Developer in Technical Support
    Xceed - Multi-talented components - http://xceed.com
  •  06-19-2012, 9:50 AM Post no. 32270 in reply to 32266

    Re: Adding Dictionaries to Application

    Hi Marc,

    I was able to figure out a solution that works better for our project since using the code behind would not be an easy task seeing as the background for the main window isn't the only place that is not changing dynamically. I created a ThemeManager that contained the brushes we needed as dependency properties that are set whenever the theme is changed. I haven't applied it to everywhere yet, but where I have it has been working perfectly.

    Thank you again for your time and responses.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.