简体   繁体   English

使用触发器更改图像获取System.Windows.Baml2006.TypeConverterMarkupExtension错误

[英]Change an image using triggers getting System.Windows.Baml2006.TypeConverterMarkupExtension error

I have written this code: 我写了这段代码:

<Image>
   <Image.Style>
      <Style TargetType="{x:Type Image}">
         <Style.Triggers>
            <DataTrigger Binding="{Binding MyProperty}" Value="Play">
               <Setter Property="Source" Value="bin\debug\Tasto Play.jpeg"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding MyProperty}" Value="Pause">
               <Setter Property="Source" Value="bin\debug\Tasto Pause.jpeg"/>
            </DataTrigger>
         </Style.Triggers>
       </Style>
   </Image.Style>
</Image>

But when I run the debug an error comes out. 但是,当我运行调试时,会出现错误。 The error is System.Windows.Baml2006.TypeConverterMarkupExtension. 该错误是System.Windows.Baml2006.TypeConverterMarkupExtension。

MyProperty is string. MyProperty是字符串。

Can someone help me? 有人能帮我吗?

Thanks, Jacopo. 谢谢,雅各布

I think that maybe is the MyProperty property type: if it is string, there is not problem, but if it is, an enum for instance, you must set the type: 我认为这可能是MyProperty属性类型:如果为字符串,则没有问题,但是,如果为枚举,则必须设置该类型:

 <Image>
   <Image.Style>
      <Style TargetType="{x:Type Image}">
         <Style.Triggers>
            <DataTrigger Binding="{Binding MyProperty}" Value="{x:Type namespace:EnumType.Play}">
               <Setter Property="Source" Value="bin\debug\Tasto Play.jpeg"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding MyProperty}" Value="{x:Type namespace:EnumType.Pause">
               <Setter Property="Source" Value="bin\debug\Tasto Pause.jpeg"/>
            </DataTrigger>
         </Style.Triggers>
       </Style>
   </Image.Style>
</Image>

Maybe could be the setter property, source (I think) is of type Uri, maybe you are not formatting well the string, maybe you must use an absulute uri (for test), but I think it is not a well formatted string path, so the Xaml's converter couldn'd create correctly the Uri type. 也许是setter属性,source(我认为)的类型是Uri,也许您没有很好地格式化字符串,也许您必须使用absulute uri(用于测试),但是我认为它不是格式化好的字符串路径,因此Xaml的转换器无法正确创建Uri类型。

Hope this could helps, or give you some idea. 希望这可以帮助您,或者给您一些想法。

For add an image as a resource in a project you have to click "Project" in the "Visual Studio Menu Bar" and click "properties of the project". 要将图像添加为项目中的资源,必须在“ Visual Studio菜单栏”中单击“项目”,然后单击“项目的属性”。 Then a window with various toolbars (like internet) will open in your screen. 然后,带有各种工具栏(例如Internet)的窗口将在屏幕上打开。 Choose the "resources toolbar" (view the image at http://i.stack.imgur.com/IjC0w.jpg ) and click the arrow near the "Add Resources" button that will be on the top of the window. 选择“资源工具栏”(在http://i.stack.imgur.com/IjC0w.jpg上查看图像),然后单击窗口顶部“添加资源”按钮附近的箭头。 Click "Add existing file" and choose the file. 单击“添加现有文件”,然后选择文件。 Then you go in the "Explore solution window" and open the "Debug folder" that will have the new resources. 然后,您进入“浏览解决方案窗口”并打开将包含新资源的“调试文件夹”。 Click with "the right button of mouse" on the new resources that you have added and click on "Properties". 在添加的新资源上单击“鼠标右键”,然后单击“属性”。 On the left of your screen will appear a "Properties window". 屏幕左侧将显示“属性窗口”。 (view the image at http://i.stack.imgur.com/NqIc1.jpg ) (在http://i.stack.imgur.com/NqIc1.jpg上查看图像)

You have to choose on "Compilating operations" the "Resources" item. 您必须在“编译操作”中选择“资源”项。 Now you can use your image as a resources in wpf. 现在,您可以将图像用作wpf中的资源。

I hope that this could helps. 我希望这会有所帮助。 Jacopo 哈科波

暂无
暂无

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

相关问题 System.Windows.Baml2006.TypeConverterMarkupExtension - System.Windows.Baml2006.TypeConverterMarkupExtension 在“ System.Windows.Baml2006.TypeConverterMarkupExtension”上提供值引发异常 - Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception 如何解决此错误:“在&#39;System.Windows.Baml2006.TypeConverterMarkupExtension&#39;上提供值” - How do I fix this error : 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' 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' 上提供值引发异常。 - '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.TypeConverterMerkupExtension。 会是什么呢? - error System.Windows.Baml2006.TypeConverterMerkupExtension. What could it be? 设置UserControl的ImageSource时发生TypeConverterMarkupExtension错误 - TypeConverterMarkupExtension error on setting ImageSource of UserControl 使用触发器更改数据库中的记录 - Change records in database by using triggers 从Windows Server 2008上的C#.NET应用程序启动MapPoint 2006/2011时出错 - Error when launching MapPoint 2006/2011 from C# .NET application on Windows Server 2008
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM