从XAML访问枚举以访问字典对象 [英] Accessing a enum from XAML to access a Dictionary-object

查看:101
本文介绍了从XAML访问枚举以访问字典对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此问题如下:

我有一个Dictionary< FormatEnum,string>我想从XAML访问此词典.
FormatEnum具有类型Small,Medium和Big,并且字符串包含图片的URL.

我尝试了以下代码:

So the problem is the following:

I have a Dictionary<FormatEnum,string> and I want to access this Dicitionary from XAML.
FormatEnum has the types Small, Medium and Big, and the string contains a URL to a picture.

I tried the following code:

<ItemsControl Name="MixControl">
 <ItemsControl.ItemTemplate>
  <DataTemplate>
   <Border CornerRadius="5" BorderThickness="2" BorderBrush="Black" Width="56" Height="56">
    <Border.Background>
     <ImageBrush ImageSource="{Binding CoverUrls[{x:Static tracks:CoverFormat.Small}]}"/>
    </Border.Background>
   </Border>
  </DataTemplate>
 </ItemsControl.ItemTemplate>
</ItemsControl>



track是名称空间引用,我在某处阅读过使用x:Static ...但它无法正常工作...
感谢您的帮助!



tracks is the namespacereference, and I read somewhere to use x:Static... But it won''t work ...
Thanks for your help!

推荐答案

您可以使用转换器将枚举更改为所需的枚举.我在WP7应用程序中使用它来将状态枚举转换为图像,例如绿色代表良好,红色代表存在错误.

WPF-使用转换器绑定到相反的布尔值 [在WPF中管道值转换器 [
You can use a converter to change the enum into whatever you need. I use this in a WP7 app to convert a status enum to an image like a green one for good or a red one for an error.

WPF - Bind to Opposite Boolean Value Using a Converter[^]
Piping Value Converters in WPF[^]


这篇关于从XAML访问枚举以访问字典对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆