C# ';在'上提供价值;System.Windows.Baml2006.TypeConverterMarkupExtension';抛出了一个异常;
标题中的异常是在WPF中打开窗口时引发的,奇怪的是,这不会发生在我的Windows 7开发机器上,也不会发生在Windows 7上部署时 我只在Windows XP上出现此错误,并且仅在第二次打开窗口时出现此错误 以下是打开窗口的代码:C# ';在'上提供价值;System.Windows.Baml2006.TypeConverterMarkupExtension';抛出了一个异常;,c#,wpf,xaml,C#,Wpf,Xaml,标题中的异常是在WPF中打开窗口时引发的,奇怪的是,这不会发生在我的Windows 7开发机器上,也不会发生在Windows 7上部署时 我只在Windows XP上出现此错误,并且仅在第二次打开窗口时出现此错误 以下是打开窗口的代码: ReportParametersWindow win = null; bool canOverWrite = _shownReports.Contains(rpt.FriendlyName); if (!(canOverWrite))
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();
<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>
以及窗口的XAML:
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();
<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>
有人有什么建议吗?这个解决方案很奇怪,但我已经找到了 我意识到错误发生在窗口的InitializeComponent()上,然后我向构造函数添加了一个try catch,并显示了异常的InnerException 我收到的错误是“无法识别图像格式” 我不知道为什么只有在XP和第二次显示窗口时才会出现这种情况,但通过用.png替换my.ico,问题得到了解决
希望这对其他人有所帮助。如果指定位置没有所需的图像,也可能出现此问题。因此,检查内部异常并添加任何可能丢失或拼写错误的图像 在我的例子中,根本原因是所有图像上的BuildAction属性都错误。我通过将BuildAction从内容更改为资源来修复它。要改进用户2125523: 如果已将图像添加到项目中,并反复检查文件拼写是否正确,请尝试重命名图像以镜像其他现有图像。构建/运行,然后将映像文件名放回原处,然后再次构建/运行 例如: 我的原始代码一直在
LargeImage=“/img/32/delete.order.png”
上抛出操作错误,即使该文件存在
<telerik:RadRibbonButton Text="Object Properties" Size="Large"
Name="PropertiesButton" IsTabStop="True"
telerik:ScreenTip.Description="Get object properties"
Click="PropertiesButton_Click"
LargeImage="/img/32/properties.png"
SmallImage="/img/16/properties.png" />
<telerik:RadRibbonButton Text="Reset Tab Order" Size="Large"
Name="ClearTabOrderButton" IsTabStop="True"
telerik:ScreenTip.Description="Reset tab order of all fields"
Click="ClearTabOrder_Click"
LargeImage="/img/32/delete.order.png"
SmallImage="/img/16/delete.order.png" />
因此,我将LargeImage=“/img/32/delete.order.png”
更改为LargeImage=“/img/32/properties.png”
,运行该程序,并将其更改回“/img/32/delete.order.png”
。最后错误消失了
仅供参考VS2012.3 Win8.1Preview我也有同样的问题,要向您的解决方案添加图像,您必须通过wizzard来完成。在解决方案资源管理器->右键单击相应的文件夹->添加现有项目->然后浏览到您的图像。这对我很管用。希望这有帮助。
谢谢你的回答 我也遇到了这个问题。。。我知道这很旧,但我最后要做的是将图像设置为资源,并始终复制。。。只有通过浏览我的/bin/Debug文件夹,我才意识到图像不在有效的路径位置在将资源字典从应用程序的根目录移动到子目录后,我出现了此异常。在我的例子中,问题是字典中样式设置器中的图像路径。在我前面加了一个正斜杠“/”之后,应用程序又开始工作了。如果您遇到类似的问题,请打开资源字典,错误将用蓝色的“Swiggly”线突出显示。在我的例子中,我已将“WpfToolkit”引用添加到我的模块中,没有必要。
删除此引用后,一切正常。奇怪 我得到这个错误是因为我的按钮命令绑定错误:
<Button Command="MyCommand" />
而不是
<Button Command="{Binding MyCommand}" />
在我的例子中,我发现新添加的图标(图像)文件没有添加到我的项目中。在我将这些新图像文件添加到我的项目中(而不仅仅是文件副本)后,问题就解决了。在我的例子中,这些文件存在于磁盘上,但在项目中没有被引用。我将它们添加到项目中,但尽管重新加载解决方案并重新启动VisualStudio,错误仍然存在
我更改了对项目中已经存在的现有文件的引用,该文件运行良好(尽管使用了错误的图形)。然后我把它改回原来的参考,它再次运行良好,但图像正确。大概是在将错误从系统中清除之前以某种方式缓存了该错误…从cs.proj文件中删除“WPFToolkit”引用
<Reference Include="WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
它应该做到这一点。尝试将图像文件的
属性的构建操作设置为资源构造函数中经常发生的异常。按钮的命令绑定不正确。
例如:
-->错误
-->Right只需转到Project>[您的项目名称]设置并将.ico文件设置为图标。现在,清单文件中提到了.ico文件,您可以使用
Icon=“[Icon file name].ico”
复制并粘贴文件名已更改。这就是我出现此错误的原因。您应该首先将图像导入到项目中
解决方案资源管理器-全部显示
然后右键单击图像并选择“包括”
现在使用
结束在我的例子中,当我
<Border Background="eeeeee">
而不是
<Border Background="#eeeeee">
(请注意missign#
)这是由于xaml中的非标准标记选项导致它被设置的
初始化组件();
在-try模式下运行-如下所示
try {
InitializeComponent();
}
catch (Exception ex) {
MessageBox.Show(ex.Message.ToString());
}
现在MessageBox((在control.axml文件中显示设置不正确的行号。(更正后只显示第一个不正确的行标记错误,然后再次运行应用程序并查看下一个错误)我在XAML中的某个地方找到了“UpdateSourceTrigger=Pr”
一定是在编辑过程中发生的
编译顺利,没有任何错误
在app.xaml.cs中的应用程序_dispatchernhandledexception中设置断点显示了错误
更正为“UpdateSourceTrigger=PropertyChanged”,世界本来应该是这样的
我在Win 10 Pro,VS2017上工作时遇到了这个错误,并且
<Window
.....
Height="450" Width="400"
Icon="../Resources/SettingsCopy.png" >