C# 使用microsoft.windows.shell时出现黑色背景

C# 使用microsoft.windows.shell时出现黑色背景,c#,wpf,xaml,C#,Wpf,Xaml,我正在使用microsoft.windows.shell自定义我的wpf窗口浏览器。在我添加datagrid之前,一切都很好。问题是窗户的外观有时会变黑。这种情况并非经常发生!有时它看起来不错,但有时它有一个黑色的背景。 以下是我的xaml代码: <Window x:Class="CodeGeneratorWpf.Config" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

我正在使用microsoft.windows.shell自定义我的wpf窗口浏览器。在我添加datagrid之前,一切都很好。问题是窗户的外观有时会变黑。这种情况并非经常发生!有时它看起来不错,但有时它有一个黑色的背景。 以下是我的xaml代码:

<Window x:Class="CodeGeneratorWpf.Config"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Config" Height="300" Width="300" Style="{StaticResource MainWindowStyle}" 
        WindowStartupLocation="CenterOwner" Loaded="Window_Loaded">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        <DataGrid Name="dataGrid" Grid.Row="0" ItemsSource="{Binding data}" 
                  AlternatingRowBackground="{StaticResource {x:Static SystemColors.ControlBrushKey}}" 
                  ClipToBounds="True" VerticalGridLinesBrush="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}"
                  HorizontalGridLinesBrush="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" 
                  LoadingRow="dataGrid_LoadingRow">
            <DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow},
                    Path=Header}"/>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>
        </DataGrid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button Name="btnSave" Grid.Column="0" Content="Save" Style="{StaticResource EmphasizeButton}" HorizontalAlignment="Stretch" Margin="25,5,25,5" Click="btnSave_Click"/>
            <Button Name="btnCancel" Grid.Column="1" Content="Cancel" Style="{StaticResource NormalButton}" Margin="25,5,25,5" Click="btnCancel_Click"/>
        </Grid>
    </Grid>
</Window>
             <!--Captions Buttons to control the window borderless-->
            <DockPanel Grid.Row="0">
                <DockPanel.Background>
                    <SolidColorBrush Color="#FF5D91DC"></SolidColorBrush>
                </DockPanel.Background>
                <Image Name="imgTitle" Source="{TemplateBinding Icon}" DockPanel.Dock="Left" Margin="5"></Image>
                <Label Content="{TemplateBinding Title}" Foreground="White"></Label>
                <ctrl:CaptionButtons  Margin="0,0,0,0" Grid.Row="0" HorizontalAlignment="Right" Type="Full"
                                    Foreground="{DynamicResource CaptionButtonColor}" FontSize="14" MarginButton="0,0,5,0"
                                    VerticalAlignment="Center" shell:WindowChrome.IsHitTestVisibleInChrome="True">

                </ctrl:CaptionButtons>
            </DockPanel>
            <ContentPresenter Margin="0" Grid.Row="1" Content="{TemplateBinding Content}"/>
        </Grid>
    </Border>

</ControlTemplate>

<Style x:Key="MainWindowStyle" TargetType="{x:Type Window}">
    <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
            <shell:WindowChrome
                    ResizeBorderThickness="6"
                    CaptionHeight="25"
                    CornerRadius="0"
                    GlassFrameThickness="0,0,0,1" />
        </Setter.Value>
    </Setter>
    <Setter Property="Template" Value="{StaticResource MainWindowControlTemplate}"/>
</Style>

主窗口样式:

             <!--Captions Buttons to control the window borderless-->
            <DockPanel Grid.Row="0">
                <DockPanel.Background>
                    <SolidColorBrush Color="#FF5D91DC"></SolidColorBrush>
                </DockPanel.Background>
                <Image Name="imgTitle" Source="{TemplateBinding Icon}" DockPanel.Dock="Left" Margin="5"></Image>
                <Label Content="{TemplateBinding Title}" Foreground="White"></Label>
                <ctrl:CaptionButtons  Margin="0,0,0,0" Grid.Row="0" HorizontalAlignment="Right" Type="Full"
                                    Foreground="{DynamicResource CaptionButtonColor}" FontSize="14" MarginButton="0,0,5,0"
                                    VerticalAlignment="Center" shell:WindowChrome.IsHitTestVisibleInChrome="True">

                </ctrl:CaptionButtons>
            </DockPanel>
            <ContentPresenter Margin="0" Grid.Row="1" Content="{TemplateBinding Content}"/>
        </Grid>
    </Border>

</ControlTemplate>

<Style x:Key="MainWindowStyle" TargetType="{x:Type Window}">
    <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
            <shell:WindowChrome
                    ResizeBorderThickness="6"
                    CaptionHeight="25"
                    CornerRadius="0"
                    GlassFrameThickness="0,0,0,1" />
        </Setter.Value>
    </Setter>
    <Setter Property="Template" Value="{StaticResource MainWindowControlTemplate}"/>
</Style>


我能得到一些帮助吗?

你能发布你的主窗口样式吗?我已经发布了主窗口样式。你能看一下吗?
             <!--Captions Buttons to control the window borderless-->
            <DockPanel Grid.Row="0">
                <DockPanel.Background>
                    <SolidColorBrush Color="#FF5D91DC"></SolidColorBrush>
                </DockPanel.Background>
                <Image Name="imgTitle" Source="{TemplateBinding Icon}" DockPanel.Dock="Left" Margin="5"></Image>
                <Label Content="{TemplateBinding Title}" Foreground="White"></Label>
                <ctrl:CaptionButtons  Margin="0,0,0,0" Grid.Row="0" HorizontalAlignment="Right" Type="Full"
                                    Foreground="{DynamicResource CaptionButtonColor}" FontSize="14" MarginButton="0,0,5,0"
                                    VerticalAlignment="Center" shell:WindowChrome.IsHitTestVisibleInChrome="True">

                </ctrl:CaptionButtons>
            </DockPanel>
            <ContentPresenter Margin="0" Grid.Row="1" Content="{TemplateBinding Content}"/>
        </Grid>
    </Border>

</ControlTemplate>

<Style x:Key="MainWindowStyle" TargetType="{x:Type Window}">
    <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
            <shell:WindowChrome
                    ResizeBorderThickness="6"
                    CaptionHeight="25"
                    CornerRadius="0"
                    GlassFrameThickness="0,0,0,1" />
        </Setter.Value>
    </Setter>
    <Setter Property="Template" Value="{StaticResource MainWindowControlTemplate}"/>
</Style>