我得到了一个包含类型列表的依赖属性的usercontrol(它位于一个库中/也试过一个正常的属性)。绑定属性到usercontrol
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
...
我也得到了数据类:
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
}
基础对象用于自动创建Dependance的属性:
[Serializable]
public abstract class BaseObject : PropertyNotifier
{
#region Members
private readonly IDictionary<string, object> _values = new Dictionary<string, object>(StringComparer.CurrentCultureIgnoreCase);
#endregion
现在我想的Data.Images绑定到customcontrol。 LstImages(“Data”是使用控件的页面上的Data数据类型的属性)。该程序毫无例外地工作,但不知何故在控制中的LstImages,我检查了几个事件,始终为空。
<controls:PicSelection Name="SelPic" LstImages="{Binding Data.Images}" Foreground="White" FontSize="16"/>
。另一方面,要做到每
<usercontrol SomeArray="{x:Static data:StaticClass.TheStrings}"/>
与静态类(涉及组织,几乎是相同的),同样的事情,就是这么简单。它甚至可以与普通属性一起使用Datacontext的设置对此没有任何影响。我忽略了什么?
什么在Visual Studio输出窗口的?你应该在那里看到绑定错误。 – 2013-11-01 12:05:53