我有一个非常简单的窗口,使用以下 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>
有什么办法可以防止这种闪烁吗?
我不认为这个现有问题是重复的。它涉及完全自定义的窗口,带有动画。
最佳答案
我知道这是旧的,但正如公认的答案所暗示的那样,这是因为调试工具。如果您不使用或不依赖 XAML 的 UI 调试工具,您会注意到性能显着提高:
Tools > Options > Debugging > General > Enable UI Debugging Tools for XAML
当然,在调试器之外运行应用程序应该会向您展示应用程序的实际性能。使用任何 IDE 作为调试器运行您的程序无疑会显着降低它的速度,这只是调试器与您的程序交互、监视它所做的一切并监听异常等方式的结果。
关于c# - 调整大小时 WPF 窗口闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40662732/