3

我有一个 WPF 应用程序,当主窗口最大化并且特定选项卡可见并且在我的选项卡控件顶部时,它经常挂起(变得完全无响应)。当窗户恢复下来时,它就像魅力一样。我能做些什么来解决这个问题?

有问题的选项卡有很多控件(文本框、图像、按钮、组合框、网格分割器、文本块、数据网格),我正在处理来自这些不同字段的事件,所以它是一个非常“忙碌”的网格。

这听起来类似于以下未解决的问题:WPF Datagrids freeze when windows Maximize ( http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/4641d825-cf80-4b76-a4f9-14183bb72bb2# 58dc7fdf-b43c-4782-833f-1d90401f1914 )

最后,让我说一下我没有按照我应该设计的那样设计应用程序,并且在主窗口中有超过 3000 行代码。我可能应该将这些繁忙的表单创建为用户控件。这会导致我的问题吗?

   <TabItem Header="Details" Name="tabDetails" Visibility="Collapsed" Width="125" TabIndex="0">
        <!--<ScrollViewer HorizontalAlignment="Stretch" Name="svrDetails" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">-->
        <Grid Name="grdDetails">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="548*" />
                    <ColumnDefinition Width="220*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="326*" />
                    <RowDefinition Height="174" />
                </Grid.RowDefinitions>
                <GridSplitter Name="gspDetailsColumns" Width="10" Grid.Column="0" ResizeDirection="Columns" TabIndex="420" />
                <GridSplitter Name="gspDetailsRows" Width="Auto" Grid.Row="0" Grid.ColumnSpan="2" ResizeDirection="Rows" Grid.Column="0" Height="10" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" TabIndex="410" />
                <ComboBox Height="52" Margin="6,6,6,0" Name="cbxStatus" VerticalAlignment="Top" Cursor="Arrow" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="26" Background="#FFF0F0F0" Grid.Column="1" SelectionChanged="cbxStatus_SelectionChanged" SelectedIndex="0" TabIndex="280">                        
                    <ComboBoxItem Content="Select status..." FontSize="20" FontStyle="Italic" />
                    <ComboBoxItem Content="Active"/>
                    <ComboBoxItem Content="Inactive" />
                    <ComboBoxItem Content="Closed" />
                </ComboBox>
                <Label Height="28" HorizontalAlignment="Left" Margin="119,78,0,0" Name="lblGuid" VerticalAlignment="Top" Visibility="Hidden" Grid.Column="1" />
                <GroupBox Header="Info" HorizontalAlignment="Stretch" Margin="6,64,0,12" Name="gbxInfo" VerticalAlignment="Stretch" Grid.Column="1">
                    <Grid>
                        <!--<TextBox HorizontalAlignment="Stretch" Name="tbkImportant" Text="" VerticalAlignment="Stretch" TextWrapping="Wrap" IsReadOnly="True" Background="#FFF0F0F0" IsTabStop="False" IsUndoEnabled="False" />-->
                    <TextBlock HorizontalAlignment="Stretch" Name="tbkImportant" VerticalAlignment="Stretch" Background="#FFF0F0F0" TextWrapping="Wrap" />
                </Grid>
                </GroupBox>
                <Grid Grid.Row="1" Name="grdDetailsNotesMacro" Grid.ColumnSpan="2">
                    <GroupBox Header="Notes" Name="gbxNotes" >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="484*" />
                                <ColumnDefinition Width="266*" />                                        
                            </Grid.ColumnDefinitions>                                    
                            <TextBox GotFocus="tbxTag_GotFocus" LostFocus="tbxTag_LostFocus" Height="23" Margin="6,6,6,35" Name="tbxTag" VerticalAlignment="Bottom" Grid.Column="1" Foreground="Gray" Text="[Add tags so to make finding notes easy]" TabIndex="350" />
                            <TextBox GotFocus="tbxNote_GotFocus" LostFocus="tbxNote_LostFocus" Grid.Column="1" Margin="6,6,6,57" Name="tbxNote" Text="[Add notes, comments, or remarks relating to this contact]" Foreground="Gray" TextWrapping="Wrap" SelectionBrush="#9B16181A" VerticalScrollBarVisibility="Auto" TabIndex="340" />
                            <Button Content="Submit" Grid.Column="1" Height="23" HorizontalAlignment="Right" Margin="0,0,128,6" Name="btnSubmit" VerticalAlignment="Bottom" Width="75" Click="btnSubmit_Click" TabIndex="360" />                                    
                            <Button Content="Cancel" Grid.Column="1" Height="23" HorizontalAlignment="Right" Margin="0,0,43,6" Name="btnCancelNote" VerticalAlignment="Bottom" Width="75" Click="btnCancelNote_Click" TabIndex="370" />
                            <DataGrid IsReadOnly="True" AutoGenerateColumns="False" Margin="6,6,0,35" Name="dtgNotes" ItemsSource="{Binding}" AlternatingRowBackground="#33000000" RowBackground="#24000000" VerticalGridLinesBrush="#00000000" ClipboardCopyMode="IncludeHeader" CanUserDeleteRows="True" CanUserAddRows="True" GridLinesVisibility="Horizontal" AreRowDetailsFrozen="True" BorderBrush="#B7000000" CanUserReorderColumns="False">
                                <DataGrid.Columns>
                                <DataGridTextColumn Header="Date" Binding="{Binding Path=Date, StringFormat={}{0:dd/MM/yyyy}}" SortDirection="Descending" />
                                <DataGridTextColumn Header="Author" Binding="{Binding Path=Author}" />
                                <DataGridTextColumn Header="Tags" Binding="{Binding Path=Tags}" />
                                <DataGridTextColumn Header="Notes" Binding="{Binding Path=Notes}"/>
                                </DataGrid.Columns>
                            </DataGrid>
                            <ComboBox Height="23" IsEditable="True" Margin="6,0,160,6" Name="cbxFilter" VerticalAlignment="Bottom" TabIndex="380" Tag="What is a tag?" />                                    
                            <Button Content="Filter" Height="23" HorizontalAlignment="Right" Margin="0,0,81,6" Name="btnFilter" VerticalAlignment="Bottom" Width="75" Click="btnFilter_Click" TabIndex="390" />
                        <Button Content="Clear" Height="23" HorizontalAlignment="Right" Margin="0,0,0,6" Name="btnClearFilter" VerticalAlignment="Bottom" Width="75" Click="btnClearFilter_Click" TabIndex="400" />
                    </Grid>
                    </GroupBox>
                </Grid>
                <ScrollViewer Margin="0,0,10,10" HorizontalAlignment="Stretch" Name="svrDetailsFull" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                    <Grid Name="grdDetailsFullPanel" Grid.Column="0" Grid.Row="0" Margin="0,0,6,6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="150*" />
                        </Grid.ColumnDefinitions>
                    <Grid Name="grdDetailsPanel">
                            <TextBox LostFocus="tbxNameContent_LostFocus" GotFocus="tbxNameContent_GotFocus" Background="#00000000" BorderBrush="#00000000" FontSize="24" FontWeight="ExtraBold" Height="52" HorizontalAlignment="Center" Margin="10,10,2,0" Name="tbxNameContent" VerticalAlignment="Top" Width="328" MouseEnter="tbxNameContent_MouseEnter" MouseLeave="tbxNameContent_MouseLeave" Text="[Enter name here]" Foreground="Gray" TabIndex="10" />
                            <TextBox GotFocus="tbxAddressContent_GotFocus" Background="#00000000" BorderBrush="#00000000" Height="28" HorizontalAlignment="Center" Margin="10,68,2,0" Name="tbxAddressContent" VerticalAlignment="Top" Width="328" TextChanged="tbxAddressContent_TextChanged" LostFocus="tbxAddressContent_LostFocus" MouseLeave="tbxAddressContent_MouseLeave" MouseEnter="tbxAddressContent_MouseEnter" Foreground="Gray" Text="[Enter address here]" TabIndex="20" />
                            <ComboBox Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" IsEditable="False" Margin="10,136,2,0" Name="cbxType" SelectedIndex="0" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="328" TabIndex="30" LostFocus="cbxType_LostFocus">
                                <ComboBoxItem Content="This is a..." />
                                <ComboBoxItem Content="Laufhaus" />
                                <ComboBoxItem Content="Club" />
                                <ComboBoxItem Content="Studio" />
                                <ComboBoxItem Content="Nightclub" />
                                <ComboBoxItem Content="Generic brothel" />
                                <ComboBoxItem Content="Person" />
                            </ComboBox>
                            <Label Content="" FontStyle="Italic" Height="28" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Margin="10,102,2,0" Name="lblCoord" VerticalAlignment="Top" VerticalContentAlignment="Top" FontSize="10" />
                            <TextBox MouseEnter="tbxMore_MouseEnter" MouseLeave="tbxMore_MouseLeave" Height="28" HorizontalAlignment="Center" Margin="169,170,44,0" Name="tbxMore" VerticalAlignment="Top" Width="204" LostFocus="tbxMore_LostFocus" TabIndex="50" />
                        <Button Content="x" Height="28" Margin="317,170,6,0" Name="btnClearMore" VerticalAlignment="Top" Background="#00000000" FontWeight="Bold" Foreground="#BC000000" Padding="0" HorizontalAlignment="Center" Width="17" VerticalContentAlignment="Center" Click="btnClearMore_Click" TabIndex="60" />
                        <ComboBox Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,170,216,0" Name="cbxOther" SelectedIndex="0" Text="" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="114" SelectionChanged="cbxOther_SelectionChanged" TabIndex="40" ItemsSource="{Binding Path=comboList}" GotFocus="cbxOther_GotFocus">
                                <!--<ComboBoxItem Content="More info..." />
                                <ComboBoxItem Content="Email" />
                                <ComboBoxItem Content="Email 2" />
                                <ComboBoxItem Content="Mobile" />
                                <ComboBoxItem Content="Telephone" />
                                <ComboBoxItem Content="Address 2" />
                                <ComboBoxItem Content="Nationality" />
                                <ComboBoxItem Content="Works at" />-->
                            </ComboBox>
                            <TextBox MouseEnter="tbxMore2_MouseEnter" MouseLeave="tbxMore2_MouseLeave" Height="28" HorizontalAlignment="Center" Margin="130,204,6,0" Name="tbxMore2" VerticalAlignment="Top" Width="204" Visibility="Collapsed" TabIndex="80" />
                        <Button Visibility="Hidden" Click="btnClearMore2_Click" Content="x" Height="28" Margin="317,204,6,0" Name="btnClearMore2" VerticalAlignment="Top" Background="#00000000" FontWeight="Bold" Foreground="#BC000000" Padding="0" HorizontalAlignment="Center" Width="17" VerticalContentAlignment="Center" TabIndex="90" />
                        <ComboBox ItemsSource="{Binding Path=comboList}" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,204,216,0" Name="cbxOther2" SelectedIndex="0" Text="" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="114" Visibility="Collapsed" SelectionChanged="cbxOther2_SelectionChanged" TabIndex="70">
                                <!--<ComboBoxItem Content="More info..." />
                                <ComboBoxItem Content="Email" />
                                <ComboBoxItem Content="Email 2" />
                                <ComboBoxItem Content="Mobile" />
                                <ComboBoxItem Content="Telephone" />
                                <ComboBoxItem Content="Address 2" />
                                <ComboBoxItem Content="Nationality" />
                                <ComboBoxItem Content="Works at" />-->
                            </ComboBox>
                            <TextBox MouseEnter="tbxMore3_MouseEnter" MouseLeave="tbxMore3_MouseLeave" Height="28" HorizontalAlignment="Center" Margin="130,238,6,0" Name="tbxMore3" VerticalAlignment="Top" Width="204" Visibility="Collapsed" TabIndex="110" />
                        <Button Visibility="Hidden" Click="btnClearMore3_Click" Content="x" Height="28" Margin="317,238,6,0" Name="btnClearMore3" VerticalAlignment="Top" Background="#00000000" FontWeight="Bold" Foreground="#BC000000" Padding="0" HorizontalAlignment="Center" Width="17" VerticalContentAlignment="Center" TabIndex="120" />
                        <ComboBox ItemsSource="{Binding Path=comboList}" SelectionChanged="cbxOther3_SelectionChanged" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,238,216,0" Name="cbxOther3" SelectedIndex="0" Text="" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="114" Visibility="Collapsed" TabIndex="100">
                                <!--<ComboBoxItem Content="More info..." />
                                <ComboBoxItem Content="Email" />
                                <ComboBoxItem Content="Email 2" />
                                <ComboBoxItem Content="Mobile" />
                                <ComboBoxItem Content="Telephone" />
                                <ComboBoxItem Content="Address 2" />
                                <ComboBoxItem Content="Nationality" />
                                <ComboBoxItem Content="Works at" />-->
                            </ComboBox>
                            <TextBox MouseEnter="tbxMore4_MouseEnter" MouseLeave="tbxMore4_MouseLeave" Height="28" HorizontalAlignment="Center" Margin="130,272,6,0" Name="tbxMore4" VerticalAlignment="Top" Width="204" Visibility="Collapsed" TabIndex="140" />
                        <Button Visibility="Hidden" Click="btnClearMore4_Click" Content="x" Height="28" Margin="317,272,6,0" Name="btnClearMore4" VerticalAlignment="Top" Background="#00000000" FontWeight="Bold" Foreground="#BC000000" Padding="0" HorizontalAlignment="Center" Width="17" VerticalContentAlignment="Center" TabIndex="150" />
                        <ComboBox ItemsSource="{Binding Path=comboList}" SelectionChanged="cbxOther4_SelectionChanged" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,272,216,0" Name="cbxOther4" SelectedIndex="0" Text="" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="114" Visibility="Collapsed" TabIndex="130">
                                <!--<ComboBoxItem Content="More info..." />
                                <ComboBoxItem Content="Email" />
                                <ComboBoxItem Content="Email 2" />
                                <ComboBoxItem Content="Mobile" />
                                <ComboBoxItem Content="Telephone" />
                                <ComboBoxItem Content="Address 2" />
                                <ComboBoxItem Content="Nationality" />
                                <ComboBoxItem Content="Works at" />-->
                            </ComboBox>
                            <TextBox MouseEnter="tbxMore5_MouseEnter" MouseLeave="tbxMore5_MouseLeave" Height="28" HorizontalAlignment="Center" Margin="130,306,6,0" Name="tbxMore5" VerticalAlignment="Top" Width="204" Visibility="Collapsed" TabIndex="170" />
                        <Button Visibility="Hidden" Click="btnClearMore5_Click" Content="x" Height="28" Margin="317,306,6,0" Name="btnClearMore5" VerticalAlignment="Top" Background="#00000000" FontWeight="Bold" Foreground="#BC000000" Padding="0" HorizontalAlignment="Center" Width="17" VerticalContentAlignment="Center" TabIndex="180" />
                        <ComboBox ItemsSource="{Binding Path=comboList}" SelectionChanged="cbxOther5_SelectionChanged" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,306,216,0" Name="cbxOther5" SelectedIndex="0" Text="" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="114" Visibility="Collapsed" TabIndex="160">
                                <!--<ComboBoxItem Content="More info..." />
                                <ComboBoxItem Content="Email" />
                                <ComboBoxItem Content="Email 2" />
                                <ComboBoxItem Content="Mobile" />
                                <ComboBoxItem Content="Telephone" />
                                <ComboBoxItem Content="Address 2" />
                                <ComboBoxItem Content="Nationality" />
                                <ComboBoxItem Content="Works at" />-->
                            </ComboBox>
                            <TextBox MouseEnter="tbxMore6_MouseEnter" MouseLeave="tbxMore6_MouseLeave" Height="28" HorizontalAlignment="Center" Margin="130,340,6,0" Name="tbxMore6" VerticalAlignment="Top" Width="204" Visibility="Collapsed" TabIndex="200" />
                        <Button Visibility="Hidden" Click="btnClearMore6_Click" Content="x" Height="28" Margin="317,340,6,0" Name="btnClearMore6" VerticalAlignment="Top" Background="#00000000" FontWeight="Bold" Foreground="#BC000000" Padding="0" HorizontalAlignment="Center" Width="17" VerticalContentAlignment="Center" TabIndex="210" />
                        <ComboBox ItemsSource="{Binding Path=comboList}" SelectionChanged="cbxOther6_SelectionChanged" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,340,216,0" Name="cbxOther6" SelectedIndex="0" Text="" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="114" Visibility="Collapsed" TabIndex="190">
                                <!--<ComboBoxItem Content="More info..." />
                                <ComboBoxItem Content="Email" />
                                <ComboBoxItem Content="Email 2" />
                                <ComboBoxItem Content="Mobile" />
                                <ComboBoxItem Content="Telephone" />
                                <ComboBoxItem Content="Address 2" />
                                <ComboBoxItem Content="Nationality" />
                                <ComboBoxItem Content="Works at" />-->
                            </ComboBox>
                            <TextBox Height="28" HorizontalAlignment="Center" Margin="130,374,6,0" Name="tbxMore7" VerticalAlignment="Top" Width="204" Visibility="Collapsed" TabIndex="230" />
                        <Button MouseEnter="btnClearMore7_MouseEnter" MouseLeave="btnClearMore7_MouseLeave" Visibility="Hidden" Click="btnClearMore7_Click" Content="x" Height="28" Margin="317,374,6,0" Name="btnClearMore7" VerticalAlignment="Top" Background="#00000000" FontWeight="Bold" Foreground="#BC000000" Padding="0" HorizontalAlignment="Center" Width="17" VerticalContentAlignment="Center" TabIndex="240" />
                        <ComboBox ItemsSource="{Binding Path=comboList}" SelectionChanged="cbxOther7_SelectionChanged" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,374,216,0" Name="cbxOther7" SelectedIndex="0" Text="" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="114" Visibility="Collapsed" TabIndex="220">
                                <!--<ComboBoxItem Content="More info..." />
                                <ComboBoxItem Content="Email" />
                                <ComboBoxItem Content="Email 2" />
                                <ComboBoxItem Content="Mobile" />
                                <ComboBoxItem Content="Telephone" />
                                <ComboBoxItem Content="Address 2" />
                                <ComboBoxItem Content="Nationality" />
                                <ComboBoxItem Content="Works at" />-->
                            </ComboBox>
                            <TextBox Height="28" HorizontalAlignment="Center" Margin="130,408,6,0" Name="tbxMore8" VerticalAlignment="Top" Width="204" Visibility="Collapsed" TabIndex="260" />
                        <Button MouseEnter="btnClearMore8_MouseEnter" MouseLeave="btnClearMore8_MouseLeave" Visibility="Hidden" Click="btnClearMore8_Click" Content="x" Height="28" Margin="317,408,6,0" Name="btnClearMore8" VerticalAlignment="Top" Background="#00000000" FontWeight="Bold" Foreground="#BC000000" Padding="0" HorizontalAlignment="Center" Width="17" VerticalContentAlignment="Center" TabIndex="270" />
                        <ComboBox ItemsSource="{Binding Path=comboList}" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,408,216,0" Name="cbxOther8" SelectedIndex="0" Text="" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="114" Visibility="Collapsed" TabIndex="250">
                                <!--<ComboBoxItem Content="More info..." />
                                <ComboBoxItem Content="Email" />
                                <ComboBoxItem Content="Email 2" />
                                <ComboBoxItem Content="Mobile" />
                                <ComboBoxItem Content="Telephone" />
                                <ComboBoxItem Content="Address 2" />
                                <ComboBoxItem Content="Nationality" />
                                <ComboBoxItem Content="Works at" />-->
                            </ComboBox>
                        </Grid>
                    <Grid Grid.Column="1" Name="grdDetailsStaticMapAndButtons" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="81*" />
                            <RowDefinition Height="95*" />
                        </Grid.RowDefinitions>
                        <Grid Margin="10,10,25,0" Name="grdImage" Background="LightGray" SizeChanged="grdImage_SizeChanged">
                            <Image Name="imgThumbnail" Stretch="Fill" SizeChanged="imgThumbnail_SizeChanged" />
                        </Grid>
                        <Button Content="Save" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="10,37,0,0" Name="btnSave" TabIndex="290" VerticalAlignment="Top" Width="75" Click="btnSave_Click" />
                        <Button Content="Add" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="90,37,0,0" Name="btnAddFromDetails" TabIndex="300" VerticalAlignment="Top" Width="35" Click="btnAddFromDetails_Click" />
                        <Button Content="Close" Grid.Row="1" Height="23" HorizontalAlignment="Right" Margin="0,37,25,0" Name="btnCancel" TabIndex="310" VerticalAlignment="Top" Width="75" Click="btnCancel_Click" />
                        <Label Content="Not right? Be more specific in the address." FontSize="10" Foreground="#FF0000AF" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,4,25,0" Name="label1" VerticalAlignment="Top" Width="207" Grid.Row="1" />
                        <Label Content="" FontSize="10" FontStyle="Italic" Grid.Row="1" Height="28" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Margin="10,67,25,0" Name="lblSaved" VerticalAlignment="Top" Width="207" />
                        <Button Background="#00000000" Content="+" Height="23" HorizontalAlignment="Right" Margin="222,68,0,108" Name="btnPlusDetails" TabIndex="320" VerticalAlignment="Center" Width="20" Click="btnPlusDetails_Click" />
                        <Button Background="#00000000" Content="-" Height="23" HorizontalAlignment="Right" Margin="222,108,0,70" Name="btnMinusDetails" TabIndex="330" VerticalAlignment="Center" Width="20" Click="btnMinusDetails_Click" />
                    </Grid>
                </Grid>
                </ScrollViewer>
            </Grid>
        <!--</ScrollViewer>-->
    </TabItem>

这是窗口元素:

<Window x:Class="mapperWPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        
    Title="Mapper" Height="600" Width="1000" Loaded="Window_Loaded" Initialized="Window_Initialized" Closing="Window_Closing" Name="wdoMain">
4

4 回答 4

2

挂起可能来自绑定/事件处理程序中的无限循环/ ...也可能来自 wpf 无法解决您设置的所有约束(width/maxWidth/... with bindings...)以显示所有内容. 所以对于 xaml:布局、大小和视觉内容:让所有事情都变得非常简单,然后放回你的真实设计,直到它坏掉。对于代码:将其拆分为一些大块,并使用允许禁用/启用这些块的布尔值。然后将这些布尔值设置为 false/true,直到它运行正常。然后将非工作代码拆分成更小的部分并启用/禁用功能,直到它运行良好,以找到循环。(布尔值可能会阻止事件触发,在函数开始时返回默认值,......取决于你在做什么)

只是一个简单的问题,如果您对调试器进行(一些)暂停,它会在哪里停止?也可能让您了解核心循环问题。如果调试器从未在代码中停止,则很可能您遇到了 xaml 问题(布局)。

于 2012-05-30T14:19:28.857 回答
1

将代码分解一下可能是明智的,因为超过 3000 行不会有帮助。此外,如果您的主窗口上有很多控件,明智的做法是查看线程以及 WPF 执行 UI 线程的方式http://msdn.microsoft.com/en-us/library/ms741870.aspx 作为渲染WPF 中的控件,尤其是 DataGrid 中的控件很慢。当我上次使用 WPF 数据网格显示大量数据时,我实现了数据分页,然后加载第一页,同时仍检索数据以帮助加快速度。

希望这可以帮助

于 2012-05-30T14:19:15.180 回答
0

WPF 使用图形芯片的资源来呈现应用程序,尤其是在调整窗口大小时。您是否尝试过在不同的硬件上运行您的应用程序?你仍然得到相同的行为吗?

此外,它可能来自最大化事件处理程序中的一些自定义代码。

于 2012-05-30T14:28:15.987 回答
0

这简直太奇怪了。请确认症状。请定义“最大化”。只有当你点击最大化按钮时?如果在调整大小模式下,您可以拖动到全尺寸吗?

请发布 XAML 的窗口部分。

据我所知,没有特定的最大化事件 - 它只是一种调整大小。

根据this这个链接,可能有不同的处理最大化过大到最大值。“优先顺序也可以确定窗口最大化时的大小” 在此处输入链接描述 这是一个范围,但您可能在 Window XAML 中有一些设置会导致冲突。

于 2012-05-30T15:03:30.333 回答