This project is read-only.

Apply theme/font/accentColor at start

Apr 28, 2013 at 2:17 AM
Hi,

Like in the demo applicaton, i want to allow users to customize the appearance of my application, but i want to remind the changes.

The settings are saved in Properties.Setting and i figured how to change the theme/font/accentColor when i click on a button.

But i can't figure how to do define the theme/font/accentColor at the application start, without any user input like a click on a button.

Thanks !
Apr 28, 2013 at 1:45 PM
Use the AppearanceManager to set theme, font and accent color in code. My suggestion is to put this in the Application.OnStartup method (in App.xaml.cs):
public partial class App : Application
{
  protected override void OnStartup(StartupEventArgs e)
  {
    base.OnStartup(e);

    AppearanceManager.Current.AccentColor = MySettings.Color;
    AppearanceManager.Current.FontSize = MySettings.FontSize;
    AppearanceManager.Current.ThemeSource = MySettings.ThemeSource;
  }
}
Apr 28, 2013 at 3:37 PM
Thanks, it works perfectly.

It's exactly what i was doing, but in the constructor of the MainWindow. I guess the AppearenceManager load the settings from the resources after the code in this constructor.
Aug 17, 2013 at 3:16 PM
Hi

I tryed this and it gives me an error saying "the name MySettings" does not exist in the current context" any idea what is wrong I even tried creating a new project from scratch using you template in visual studio but still the same error ?
Aug 18, 2013 at 12:36 AM
justinfourie wrote:
Hi

I tryed this and it gives me an error saying "the name MySettings" does not exist in the current context" any idea what is wrong I even tried creating a new project from scratch using you template in visual studio but still the same error ?
justinfourie understand that MySettings is the context of the settings file that kozw has on his example. You need to adjust this to the settings file you have created in your solution.
Aug 20, 2013 at 8:38 PM
O ok thanks I see now sorry all sorted late night coding fail :)
Dec 13, 2013 at 10:17 AM
I'm trying to change accent color:
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            AppearanceManager.Current.AccentColor = Colors.Black;
        }
But treeview control selected item color appears to be default (blue), not black. What am I doing wrong?
Xaml:
<Window x:Class="WpfApplication18.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mui="http://firstfloorsoftware.com/ModernUI"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <ResourceDictionary>
            <!-- WPF 4.0 workaround -->
            <Style TargetType="{x:Type Rectangle}" />
            <!-- end of workaround -->
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
                <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid >
        <TreeView>
            <TreeViewItem Header="Item 1">
                <TreeViewItem Header="Item 1.1" />
                <TreeViewItem Header="Item 1.2" />
                <TreeViewItem Header="Item 1.3" />
            </TreeViewItem>
        </TreeView>
    </Grid>
</Window>
Jan 30, 2014 at 11:00 PM
Lebowsker wrote:
justinfourie understand that MySettings is the context of the settings file that kozw has on his example. You need to adjust this to the settings file you have created in your solution.
I created a settings file, but now i'm getting an error about convert from system.drawing.color to system.windows.media.color. I couldn't handle it. Any solution?
Jan 31, 2014 at 12:36 AM
something as follows should get you there

My.Settings.AccentColour is a System.Drawing.Colour
AppearanceManager.Current.AccentColor is a System.Windows.Media.Colour

To convert use the FromArgb

FirstFloor.ModernUI.Presentation.AppearanceManager.Current.AccentColor = System.Windows.Media.Color.FromArgb(My.Settings.AccentColour.A, My.Settings.AccentColour.R, My.Settings.AccentColour.G, My.Settings.AccentColour.B)
Jan 31, 2014 at 12:08 PM
I'm using C#. Is there any the equivalent code in C# for my.settings? Also, can't we use a save button or something like that. Yesterday I tried this but I couldn't see how to combobox works. I'll give it another shot today.
Feb 7, 2014 at 1:50 PM
Hi okami,

You can see here : Persisting Modern UI for WPF Styles
Apr 1, 2014 at 8:57 AM