Reputation: 5203
I have added a Dictionary property named Xy in the user control I developed. The dictionary type is Dictionary<int, string>
While using the user control in a wpf application, I need to add these items to the dictionary from the xaml file of the application.
0,"a.bmp"
1,"b.bmp"
How can I do this?
The user control code is given below
public partial class UserControl1 : UserControl
{
private Dictionary<int, string> xy = new Dictionary<int, string>();
public Dictionary<int, string> Xy
{
get
{
return xy;
}
set
{
xy = value;
}
}
}
Edit
The basic idea is to add a set of value, image name pairs to the disctionary from the xaml file. Sample pairs are given below
0,"a.bmp"
1,"b.bmp"
If value 0 is set some property, show image a.bmp
If value 1 is set some property, show image b.bmp
Is that possible?
Upvotes: 2
Views: 1016
Reputation: 21599
This may work:
<u:UserControl1>
<u:UserControl1.Xy>
<sys:String x:Key="0">a.bmp</sys:String>
<sys:String x:Key="1">b.bmp</sys:String>
</u:UserControl1.Xy>
</u:UserControl1>
Not sure about the key conversion though, you may need to use something like <x:Key><sys:Int32>0</sys:Int32></x:Key>
for that. But try the simpler approach first.
Upvotes: 2