I got a usercontrol containing a dependancy property of the typ list (this sits inside an library / also tried with a normal property).
public partial class PicSelection : UserControl
{
#region Properties
public static readonly DependencyProperty LstImagesProperty = DependencyProperty.Register("LstImages", typeof(List<string>), typeof(PicSelection), new FrameworkPropertyMetadata(null));
// .NET Property wrapper
public List<string> LstImages
{
get { return (List<string>)GetValue(LstImagesProperty); }
set { SetValue(LstImagesProperty, value); }
}
#endregion
...
I also got a DataClass:
public class Data : BaseObject
{
#region Members
public List<string> Images { set { SetValue("Images", value); } get { return (GetValue<List<string>>("Images")); } }
#endregion
#region Construction
public GameData()
{
Images = new List<string>();
Images.Add("pack://application:,,,/TestApp;component/Content/Images/Pictures/0002.jpg");
}
#endregion
}
Base object is used to automatically create dependance properties:
[Serializable]
public abstract class BaseObject : PropertyNotifier
{
#region Members
private readonly IDictionary<string, object> _values = new Dictionary<string, object>(StringComparer.CurrentCultureIgnoreCase);
#endregion
Now I want to bind the Data.Images to the customcontrol.LstImages ("Data" is a property of typ Data on the page, where the control is used). The program works without exception but somehow the LstImages in the control, I checked it on several events, is always null.
<controls:PicSelection Name="SelPic" LstImages="{Binding Data.Images}" Foreground="White" FontSize="16"/>
On the other hand, to do the same thing with a static class (which is almost the same relating to the organisation) per
<usercontrol SomeArray="{x:Static data:StaticClass.TheStrings}"/>
is so simple. It even works with normal properties. The setting of Datacontext to this changes nothing by the way. Have I overlooked something?