c# - 调整大小时 WPF 窗口闪烁

标签 c# wpf

我有一个非常简单的窗口,使用以下 XAML 定义(当前 View 模型中没有逻辑):

<Window x:Class="WpfViewer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:local="clr-namespace:WpfViewer"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Title="MainWindow"
        Width="525"
        Height="350"
        d:DataContext="{d:DesignInstance local:MainWindowVm}"
        mc:Ignorable="d">
    <Grid Margin="8">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="8" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0"
                    Grid.Column="0"
                    Grid.ColumnSpan="3"
                    Orientation="Horizontal" Margin="0,0,0,8">
            <TextBlock Text="Object" />
            <!--  breadcrumbs  -->
        </StackPanel>
        <Border Grid.Row="1"
                Grid.Column="0"
                BorderBrush="Black"
                BorderThickness="1" />
        <GridSplitter Grid.Row="1"
                      Grid.Column="1"
                      Width="8"
                      Background="{DynamicResource {x:Static SystemColors.WindowBrush}}"
                      ResizeBehavior="PreviousAndNext" />
        <Border Grid.Row="1"
                Grid.Column="2"
                BorderBrush="Black"
                BorderThickness="1" />
    </Grid>
</Window>

当用户调整窗口大小时,窗口的新区域闪烁黑色。 enter image description here

有什么办法可以防止这种闪烁吗?


我不认为这个现有问题是重复的。它涉及完全自定义的窗口,带有动画。

Prevent WPF window flicker

最佳答案

我知道这是旧的,但正如公认的答案所暗示的那样,这是因为调试工具。如果您不使用或不依赖 XAML 的 UI 调试工具,您会注意到性能显着提高:

Tools > Options > Debugging > General > Enable UI Debugging Tools for XAML

当然,在调试器之外运行应用程序应该会向您展示应用程序的实际性能。使用任何 IDE 作为调试器运行您的程序无疑会显着降低它的速度,这只是调试器与您的程序交互、监视它所做的一切并监听异常等方式的结果。

关于c# - 调整大小时 WPF 窗口闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40662732/

相关文章:

c# - XAML 重用标记 block

c# - WPF圆形边框按钮,响应单击颜色变化

c# - WPF ListBox Binding 每行产生一个字符

c# - amb-operator 的非确定性选择

c# - 如何关闭Kinect USB口的句柄以防止VisualStudio死机?

c# - 绑定(bind)不响应 PropertyChanged

wpf - 在开始拖动之前,ListView丢失选择

c# - 为什么我无法调用 WriteLogDataToDb 方法?

c# - 如何在 C# 中使用 Powershell 创建变量

c# - WPF/控制台混合应用程序