Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

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


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

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900