当我在WPF中打开一个窗口时会抛出标题中的异常,奇怪的是这不会发生在我的Windows 7开发机器上,也不会发生在它部署在Windows 7上时。
我只在 Windows XP 上收到此错误,并且仅在第二次打开窗口时出现。
这是打开窗口的代码:
ReportParametersWindow win = null;
bool canOverWrite = _shownReports.Contains(rpt.FriendlyName);
if (!(canOverWrite))
win = new ReportParametersWindow(rpt.FriendlyName, rpt.ReportParameters, canOverWrite);
else
win = new ReportParametersWindow(rpt.FriendlyName, (container.ParametersWindow as ReportParametersWindow).Controls, canOverWrite);
win.ShowDialog();
以及窗口的 XAML:
<Window xmlns:my="clr-namespace:MHA.Modules.Core.Controls;assembly=MHA.Modules.Core"
x:Class="MHA.Modules.Reports.Views.ReportParametersWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Parameters" Height="500" Width="600" MinWidth="500" MaxHeight="500"
Icon="/MHA.Modules.Reports;component/Images/Parameters.ico" SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterScreen"
xmlns:odc="clr-namespace:Odyssey.Controls;assembly=Odyssey" Closed="Window_Closed">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0" Name="ScrollViewer1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" CanContentScroll="True">
<StackPanel Name="ParameterStack">
<my:LocationCtl Text="Parameters for report - " Name="loc"/>
</StackPanel>
</ScrollViewer>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<CheckBox ToolTip="This will replace the first report of the same type that was shown." Name="chkOverwrite" Content="Overwrite old" VerticalAlignment="Center" Margin="5,0"></CheckBox>
<Button Grid.Column="2" HorizontalAlignment="Right" Margin="5,0" Height="30" Style="{StaticResource DionysusButton}" Width="100" IsDefault="True" Click="Button_Click">
<StackPanel Orientation="Horizontal">
<Image Source="/MHA.Modules.Reports;component/Images/Success.png"></Image>
<TextBlock Margin="5,0" Text="Accept" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</Button>
</Grid>
</Grid>
有人有建议吗?