Mahapps.Metro changes the theme of unified management

Is there a way to change the theme (light / dark) based on each control in the mahapps metro? My problem is that I have a window that uses the Light theme, but I have a part of it that has a really dark background and I can’t get the ComboBox to display correctly, the little arrow remains black even if I change the background color is black and the foreground is white. I found links about changing this arrow with some pretty serious trickery around control templates, but not much luck yet ... To make things a little more complicated, the combobox is inside the itemmemplate element for the list.

I have a popup window elsewhere and I realized that it has exactly that type of style for combobox because it uses a dark theme. That's why I ask, is there an easy way to switch the theme to individual controls?

Thank!

+4
source share
1 answer

Not sure if I am following this question correctly. So, do you want yours to ComboBoxuse the Dark theme when the parent control uses the Light theme?

If so, then it is quite simple. Within the control within it, resources add the DarkTheme resource.

Say we got

 <Application.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      ...
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Application.Resources>

Now almost everything in your application will use a light theme. However, if we define ComboBox, for example:

<ListBox>
  <!-- This is just for an example so you would ofc have this defined in the ItemTemplate normally -->
  <ListBoxItem>
    <ComboBox>
      <ComboBox.Resources>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
      </ComboBox.Resources>
      <ComboBoxItem Content="A" />
      <ComboBoxItem Content="A" />
      <ComboBoxItem Content="A" />
    </ComboBox>
  </ListBoxItem>
  <ListBoxItem Content="A" />
  <ListBoxItem Content="A" />
</ListBox>

BaseDark.xaml ComboBox, .

enter image description here

, , - Brush magic:) Control - , , . , .

, BaseLight.xaml BaseDark.xaml .

, , , .

+5

Source: https://habr.com/ru/post/1539589/


All Articles