我有一个 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">