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

时间:2014-12-02 04:57:29

标签: c# wpf xaml

我正在使用microsoft.windows.shell来自定义我的wpf窗口chrome。在添加数据网格之前,一切都很好。问题是窗户的外观有时会变黑。这种情况不会经常发生!有时它看起来很好但有时它有黑色背景。 这是我的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>

MainWindowStyle:                                                                                                                                                                                                                                                                                                                 

             <!--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>

我可以得到一些帮助吗?

0 个答案:

没有答案