当我在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();
Run Code Online (Sandbox Code Playgroud)
和窗口的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>
Run Code Online (Sandbox Code Playgroud)
有没有人有建议?
Chr*_*yks 46
解决方案非常奇怪,但我已经弄清楚了.
我意识到错误发生在窗口的InitializeComponent()上,然后我向构造函数添加了一个try catch并显示了Exception的InnerException.
我收到的错误是"图像格式无法识别".
我不知道为什么这只发生在XP上,第二次显示窗口,但是用.png替换我的.ico,问题就解决了.
希望这有助于某人.
Kev*_*vin 26
我刚刚遇到这个问题......我知道这已经过时了,但我最终要做的就是将图像设置为Resource,并始终复制...只有浏览我的/ bin/Debug文件夹我才意识到图像不在有效的路径位置
小智 8
我收到此错误,因为我的Button的命令绑定错误:
<Button Command="MyCommand" />
Run Code Online (Sandbox Code Playgroud)
代替
<Button Command="{Binding MyCommand}" />
Run Code Online (Sandbox Code Playgroud)