C# Can';t更改treeview的背景色使用Mahapp

C# Can';t更改treeview的背景色使用Mahapp,c#,wpf,treeview,C#,Wpf,Treeview,我试图更改treeview的颜色,但颜色无法填充整个treeview 总是这样的: 我的.xaml <Grid > <TreeView x:Name="treeView" BorderThickness="0" Style="{x:Null}" Height="Auto" Width="Auto" Background="#38364E"

我试图更改treeview的颜色,但颜色无法填充整个treeview

总是这样的:

我的.xaml

<Grid >
    <TreeView x:Name="treeView"
              BorderThickness="0"
              Style="{x:Null}"
              Height="Auto" Width="Auto"
              Background="#38364E"
              Foreground="#38364E"
              Margin="15,15,15,15">

    </TreeView>
</Grid>

我的App.xaml

<Application x:Class="Rodemeyer.Dot2Wpf.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml" DispatcherUnhandledException="Application_DispatcherUnhandledException" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml">
        </ResourceDictionary>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml">
        </ResourceDictionary>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml">
        </ResourceDictionary>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml">
        </ResourceDictionary>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml">
        </ResourceDictionary>
        <ResourceDictionary Source="ResourcesDictionary/ButtonStyle.xaml">
          <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:Rodemeyer.Dot2Wpf.ViewModel" />
        </ResourceDictionary>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>

我猜treeview使用mahapp的颜色样式,它不能手动更改背景颜色


当使用mahapp框架时,是否有人知道如何为treeview填充颜色

您可以通过覆盖模板中使用的某些资源来更改颜色,例如:

<TreeView x:Name="treeView"
          BorderThickness="0"
          Height="Auto" Width="Auto"
          Margin="15,15,15,15">
    <TreeView.Resources>
        <SolidColorBrush x:Key="MahApps.Brushes.ThemeBackground" Color="#38364E" />
        <SolidColorBrush x:Key="MahApps.Brushes.Text" Color="Red" />
        <!-- mouse over: -->
        <SolidColorBrush x:Key="MahApps.Brushes.Accent3" Color="Green" />
        <!-- selection: -->
        <SolidColorBrush x:Key="MahApps.Brushes.Accent" Color="Orange" />
    </TreeView.Resources>
</TreeView>


你的
App.xaml
文件中有什么?@mm8我更新App.xaml对于我的问题,里面没有什么特别的,只使用mahapp风格的颜色样式/Accents/Blue.xaml“。我想这是一个问题,但我不知道如何修复它。我尝试使用您的代码,但它不起作用,似乎它仍然使用mahaap颜色样式。你知道你在用哪个版本的MahApps.Metro吗?看起来是一个旧的。尝试升级到最新版本,并根据修改您的
App.xaml
。是的,我使用旧版本mahapp,因为我尝试使用最新版本,但无法安装。它总是说MahApps.Metro.dll中的“System.IO.FileNotFoundException”…无法加载文件或程序集“Microsoft.Xaml.Behaviors…”。。。系统找不到指定的文件。“为什么它不能应用于旧版本。是的,你完全正确。当我将mahapp升级到2.0.1:)时,它正在工作。非常感谢,非常感谢。:)