Here is my data type:
using System;
namespace UI
{
public class AddressType
{
public byte ID { get; set; }
public string Name { get; set; }
}
}
Here is my collection:
using System.Collections.ObjectModel;
namespace UI
{
public class AddressTypes : ObservableCollection<AddressType>
{
}
}
Here is my XAML from my UserControl.Resources section of my page:
<local:AddressTypes x:Name=”AddressTypesList”>
<local:AddressType ID="0" Name="Select"/>
<local:AddressType ID="1" Name="Office"/>
<local:AddressType ID="2" Name="Shipping"/>
<local:AddressType ID="3" Name="Warehouse"/>
<local:AddressType ID="4" Name="Home"/>
<local:AddressType ID="5" Name="Foreign"/>
</local:AddressTypes>
When I try to assign a value in XAML to the ID property, I get a AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 10 Position: 35] error. If I change the data type of the ID property to int, all is well. Doesn’t Silverlight support the byte data type?
Specifying byte values using the attribute syntax does not appear to work. However, it is possible to specify byte values using the property element syntax.
Add the the following xmlns declaration:
The you should be able to specify the byte properties like so:
This is kind of messy though, so what you can do is implement a custom type converter, and mark up your property with an attribute to use that type converter.
The TypeConverter should look something like:
And you then want to modify your class so that the property points to this type converter:
Now you should be able to use the regular property attribute syntax: