System.Windows.Baml2006.TypeConverterMarkupExtension“关于提供价值'引发了异常。” [英] 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.'
问题描述
当我打开WPF窗口标题中抛出异常,奇怪的是,这不会发生在我的Windows 7开发计算机上,也当它被部署在Windows 7中它发生了。
The exception in the title is thrown when I open a window in WPF, the strange thing is that this does not happen on my Windows 7 development machine nor does it happen when it is deployed on Windows 7.
我只得到在Windows XP的这个错误,并且只有我打开窗户的第二次。
I only get this error on Windows XP, and only the second time that I open the window.
下面是代码在打开的窗口:
Here is the code to open the window:
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>
有没有人有什么建议?
推荐答案
该解决方案是一个相当奇怪的一个,但我有它想通了。
The solution is quite a weird one but I have it figured out.
我认识到错误是在窗口在InitializeComponent()发生,我再补充一个尝试捕捉到构造和表现异常的的InnerException。
I realized that the error was occurring on the InitializeComponent() of the window, I then added a try catch to the constructor and showed the InnerException of the Exception.
这是我收到的错误是图像格式无法识别。
The error that I received is "Image format not recognized".
我不知道为什么会这样只有在Windows XP,并且显示在窗口中的第二次,但通过与.png格式问题得到解决更换我的.ICO。
I have no idea why this happens only on XP and the second time that the window is shown but by replacing my .ico with a .png the problem was resolved.
希望这可以帮助别人。
这篇关于System.Windows.Baml2006.TypeConverterMarkupExtension“关于提供价值'引发了异常。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!