简体   繁体   English

'在 'System.Windows.Baml2006.TypeConverterMarkupExtension' 上提供值引发异常。

[英]'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.'

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.当我在WPF中打开一个window时抛出了标题中的异常,奇怪的是我的Windows 7开发机上并没有发生这种情况,部署在Windows 7上也没有发生。

I only get this error on Windows XP, and only the second time that I open the window.我只在 Windows XP 上遇到这个错误,而且是我第二次打开 window。

Here is the code to open the window:下面是打开 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();

And the XAML for the window: XAML 为 window:

<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>

Does anyone have suggestions?有人有建议吗?

The solution is quite a weird one but I have it figured out.解决方案很奇怪,但我已经弄清楚了。

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.我意识到错误发生在窗口的 InitializeComponent() 上,然后我向构造函数添加了一个 try catch 并显示了异常的 InnerException。

The error that I received is "Image format not recognized".我收到的错误是“无法识别图像格式”。

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.我不知道为什么这只发生在 XP 和第二次显示窗口时,但通过用 .png 替换我的 .ico 问题解决了。

Hope this helps someone.希望这可以帮助某人。

我也刚遇到这个问题...我知道这很旧,但我最终要做的是将图像设置为资源,并始终复制...只有通过浏览我的 /bin/Debug 文件夹我才意识到图像不在有效的路径位置

This problem can also occur if the required image is not available at the specified location.如果所需的图像在指定位置不可用,也会出现此问题。 So Check the inner exception and add any image that might have been missed or misspelled.所以检查内部异常并添加任何可能遗漏或拼写错误的图像。

I got this error because my Command Binding of a Button was wrong:我收到此错误是因为我的按钮命令绑定错误:

<Button Command="MyCommand" />

instead of代替

<Button Command="{Binding MyCommand}" />

You Should first Import Image to your project Solution Explorer - Show All您应该首先将图像导入到您的项目解决方案资源管理器 - 显示全部

在此处输入图片说明

then Right Click on the image and select Include然后右键单击图像并选择包括

在此处输入图片说明

Now Use end现在使用结束

In my case the root cause was wrong BuildAction property on all images.在我的情况下,根本原因是所有图像上的 BuildAction 属性错误。 I fixed it by changing BuildAction from Content to Resource.我通过将 BuildAction 从 Content 更改为 Resource 来修复它。

I got this exception after moving my Resource Dictionary from root of my application to a subdirectory.将我的资源字典从应用程序的根目录移动到子目录后,我得到了这个异常。 In my case the problem were Image paths inside my Style setters inside the dictionary.在我的情况下,问题是字典中样式设置器中的图像路径。 After I preceded them with a forward slash '/', the application started to work again.在我前面加上一个正斜杠“/”之后,应用程序又开始工作了。 If you're having a similar problem, open the resource dictionary, and the error will be highlighted with the blue 'squiggly' line.如果您遇到类似问题,请打开资源字典,错误将用蓝色“波浪线”突出显示。

In my case, I have added 'WpfToolkit' refrence to my module, and there is no need.就我而言,我已将“WpfToolkit”引用添加到我的模块中,并且没有必要。 After deleting this reference, everything was ok.删除此引用后,一切正常。 Strange!奇怪的!

Just go to Project>[Your Project Name] Settings and set your .ico file as icon now your .ico file is mentioned in your manifest file and you can simply include your .ico file in your XAML file using只需转到 Project>[Your Project Name] Settings 并将您的 .ico 文件设置为图标,现在您的 .ico 文件已在您的清单文件中提及,您只需使用以下命令将 .ico 文件包含在您的 XAML 文件中

Icon="[icon file name].ico" Icon="[图标文件名].ico"

<Window  x:Class="[Your project's name].MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="" Height="500" Width="720"
     Icon="[your icon's name].ico">

In my case, I found the mew added icon(image) file is not added into my project.就我而言,我发现 mew 添加的图标(图像)文件未添加到我的项目中。 It is resolved after I added these new image files into my project, not just file copy.在我将这些新的图像文件添加到我的项目中后,它就解决了,而不仅仅是文件复制。

In my case the files existed on disk but were not referenced in the project.就我而言,文件存在于磁盘上,但未在项目中引用。 I added them to the project but the error persisted despite reloading the solution and restarting Visual Studio.我将它们添加到项目中,但尽管重新加载解决方案并重新启动 Visual Studio,错误仍然存​​在。

I changed the references to an existing file that was already in the project and it ran fine (albeit with the wrong graphic).我更改了对项目中已有文件的引用,并且运行良好(尽管图形错误)。 I then changed it back to the original reference and it ran fine again but with the correct image.然后我将它改回原始参考,它再次运行良好,但图像正确。 Presumably the error was getting cached somehow until it was flushed out of the system...据推测,错误以某种方式被缓存,直到它被刷新出系统......

Remove the "WPFToolkit" reference from your cs.proj file.从 cs.proj 文件中删除“WPFToolkit”引用。

<Reference Include="WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

It should do the trick.它应该可以解决问题。

copy and paste the file name is changed.复制并粘贴文件名已更改。 that's why I get this error.这就是我收到此错误的原因。

well, in my case I added the new photos to the image Folder in FileExplore while image folder was added to the project while ago.好吧,就我而言,我将新照片添加到 FileExplore 中的图像文件夹,而图像文件夹不久前已添加到项目中。 and there wasn't any problem with the image path in the project.并且项目中的图像路径没有任何问题。 but when I build the project I face to the same error.但是当我构建项目时,我遇到了同样的错误。 then I add those new photos to project by right click on the image folder and add the existing item and selected new photos.然后我通过右键单击图像文件夹将这些新照片添加到项目中,并添加现有项目和选择的新照片。 then I cleaned the solution and build it again .然后我清理了解决方案再次构建它

There are many ways to cause this issue.导致此问题的方法有很多。 Since the exception isn't specific.由于异常不是特定的。 Here is a list of solutions to try from this thread.这是从该线程尝试的解决方案列表。

Firstly , you can try/catch the InitializeComponent() call which is throwing the exception to get more details about what happened.首先,您可以try/catch引发异常的InitializeComponent()调用以获取有关发生的事情的更多详细信息。

  • If the image is an icon (.ico) file use an image (.png) or equivalent instead如果图像是图标 (.ico) 文件,请改用图像 (.png) 或等效文件
    • In some cases .ico files are problematic - I was using .NETCore在某些情况下.ico文件有问题 - 我使用的是 .NETCore
  • Make sure your image file has a build action of Resource or Embedded Resource确保您的图像文件具有ResourceEmbedded Resource的构建操作

    The resource files described in this section are different than the resource files described in XAML Resources and different than the embedded or linked resources described in Manage Application Resources (.NET).本节中描述的资源文件不同于 XAML 资源中描述的资源文件,也不同于管理应用程序资源 (.NET) 中描述的嵌入或链接资源。 - MSDN - MSDN

  • Ensure your reference to the file is spelled and pathed correctly确保您对文件的引用拼写路径正确

    • Example: "/Resources/logo.png" if you have a folder at the project level示例:“/Resources/logo.png”如果您在项目级别有一个文件夹
      • Notice the prefix / .注意前缀/
  • Colors codes in the xaml file missing the hashtag prefix "#000FE0" xaml 文件中的颜色代码缺少主题标签前缀"#000FE0"

In my case, another program was using the image and somehow was blocking the access.就我而言,另一个程序正在使用该图像并以某种方式阻止访问。 I mad a copy and this worked.我疯了一个副本,这奏效了。

<Window
.....
     Height="450" Width="400" 
     Icon="../Resources/SettingsCopy.png" >

To improve upon user2125523:改进 user2125523:

If you've added the image to the project and checked and double checked that the file spelling is correct, try renaming the image to mirror a different existing image.如果您已将图像添加到项目并检查并仔细检查文件拼写是否正确,请尝试重命名图像以镜像不同的现有图像。 Build/run, then put your image file name back and build/run again.构建/运行,然后将您的图像文件名放回并再次构建/运行。

For example: My original code kept throwing the OP error on LargeImage="/img/32/delete.order.png" even though this file exists.例如:即使这个文件存在,我的原始代码仍然在LargeImage="/img/32/delete.order.png"上抛出 OP 错误。

<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" />

So, I changed LargeImage="/img/32/delete.order.png" to LargeImage="/img/32/properties.png" , ran the program, and changed it back to "/img/32/delete.order.png" .因此,我将LargeImage="/img/32/delete.order.png"更改为LargeImage="/img/32/properties.png" ,运行程序,并将其改回"/img/32/delete.order.png" Finally the error was gone.最后错误消失了。

FYI VS2012.3 Win8.1Preview仅供参考 VS2012.3 Win8.1Preview

I had the same issue and to add an image to you solution you have to do it through the wizzard.我遇到了同样的问题,要将图像添加到您的解决方案中,您必须通过向导来完成。 In the solution explorer -> right click on the appropriate folder-> add existing Item -> and then browse to your image.在解决方案资源管理器中 -> 右键单击​​相应的文件夹 -> 添加现有项目 -> 然后浏览到您的图像。 That worked for me.那对我有用。 Hope this helps.希望这可以帮助。 Thanks for you answers.谢谢你的回答。

尝试将 Image 文件PropertyBuild Action设置为Resource

Exception used to occur within constructor.异常曾经发生在构造函数中。 Button's command binding was incorrect. Button 的命令绑定不正确。 Eg: <Button Command="MyCommand" /> --> Wrong <Button Command="{Binding MyCommand}" /> --> Right例如: <Button Command="MyCommand" /> --> 错误的<Button Command="{Binding MyCommand}" /> --> 正确

In my case, I got this error when I had就我而言,当我遇到这个错误时

<Border Background="eeeeee">

instead of代替

<Border Background="#eeeeee">

(notice the missign # ) (注意错号#

I found "UpdateSourceTrigger=Pr" somewhere in my XAML.我在 XAML 的某处找到了“UpdateSourceTrigger=Pr”。

Must have happened during editing.一定是在编辑过程中发生的。

Compiling went OK, no error then whatsoever.编译顺利,没有任何错误。

Setting a BreakPoint in Application_DispatcherUnhandledException in app.xaml.cs revealed the error.在 app.xaml.cs 中的 Application_DispatcherUnhandledException 中设置 BreakPoint 揭示了错误。

Corrected to "UpdateSourceTrigger=PropertyChanged" and the world was at it should have been.更正为“UpdateSourceTrigger=PropertyChanged”,世界本应如此。

I work on Win 10 Pro, VS2017我在 Win 10 Pro、VS2017 上工作

I encountered this error and figured out that the Image Source path format has a mistake.遇到这个错误,发现是Image Source路径格式有误。 a forward slash / was added as follows:添加了正斜杠/如下:

Source="/TestProject;component/Images//hat_and_book.png

I removed that extra slash and the error had gone.我删除了那个额外的斜线,错误就消失了。

I got the same error message, then I find this solution: Image not displaying at runtime C# WPF我得到了同样的错误信息,然后我找到了这个解决方案: Image not displayed at runtime C# WPF

Find your folder:Go to properties of the added image, set Build Action =>as Resource and Copy To Output Directory =>as Copy if newer.找到您的文件夹:Go 到添加图像的属性,设置 Build Action => as Resource 和 Copy To Output Directory => as Copy if newer。

In My case I have wrote a border tag with height property then i had to remove the value leaving the property like this在我的例子中,我写了一个带有高度属性的边框标签,然后我不得不像这样删除离开属性的值

 <Border Background="{StaticResource MainBackgroundBrush}" BorderThickness="1" Height=""> </Border>

The Compiler gave me the same error but the IDE have no problem so after some hard search i have found it.编译器给了我同样的错误,但 IDE 没有问题,所以经过一番艰苦的搜索,我找到了它。 so make sure every property is properly set.因此请确保正确设置每个属性。 I hope this would be useful for anyone.我希望这对任何人都有用。

it is caused by Non-standard tag option in xaml to find it set InitializeComponent();它是由xaml中的非标准标签选项引起的,发现它设置了InitializeComponent(); Function in - try mode - like this功能在 - 尝试模式 - 像这样

 try { 
InitializeComponent(); 
} 
catch (Exception ex) { 
MessageBox.Show(ex.Message.ToString()); 
}

now MessageBox(( show line number with incorrect setting in control .axml file.(it just show first incorrect line tag error after Corrected it then run app again and see next one)现在 MessageBox((在控制 .axml 文件中显示设置不正确的行号。(它只是在更正后显示第一个不正确的行标记错误,然后再次运行应用程序并查看下一个)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在“ System.Windows.Baml2006.TypeConverterMarkupExtension”上提供值引发异常 - Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception &#39;为&#39;System.Windows.Baml2006.TypeConverterMarkupExtension&#39;提供价值,引发了一个异常。 行号&#39;49&#39;和行位置&#39;38&#39; - 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '49' and line position '38' System.Windows.Baml2006.TypeConverterMarkupExtension&#39;抛出异常。&#39; 行号&#39;6&#39;和行位置&#39;10 - System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '6' and line position '10 System.Windows.Baml2006.TypeConverterMarkupExtension - System.Windows.Baml2006.TypeConverterMarkupExtension 如何解决此错误:“在&#39;System.Windows.Baml2006.TypeConverterMarkupExtension&#39;上提供值” - How do I fix this error : 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' 使用触发器更改图像获取System.Windows.Baml2006.TypeConverterMarkupExtension错误 - Change an image using triggers getting System.Windows.Baml2006.TypeConverterMarkupExtension error "Xaml 异常:“在 &#39;System.Windows.Markup.StaticResourceHolder&#39; 上提供值引发异常。”" - Xaml exception: "Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception." 错误System.Windows.Baml2006.TypeConverterMerkupExtension。 会是什么呢? - error System.Windows.Baml2006.TypeConverterMerkupExtension. What could it be? WPF&#39;设置属性&#39;System.Windows.ResourceDictionary.DeferrableContent&#39;引发了一个异常。 - WPF 'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.' WPF 应用程序错误“设置属性“System.Windows.ResourceDictionary.Source”引发异常。 - WPF application error 'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM