【问题标题】:Binding value on custom control with TemplateBinding使用 TemplateBinding 在自定义控件上绑定值
【发布时间】:2011-05-05 23:37:28
【问题描述】:

我创建了一个自定义控件 A,带有 ControlTemplate 部分,其中:

<myOtherControl DataContext="{TemplateBinding ItemsSource}"/>, 

而 MyOtherControl 有:

<DataGrid ItemsSource={Binding VMDataProperty}/>

在我看来,我有:

<A ItemsSource="{Binding VMData}"/>

我认为这应该有效,但它没有;

有什么想法吗?

编辑:

 ViewModelData VMData = new ViewModelData() 
{
    List<Person> VMDataProperty {get; set;}
    string Name { get; set;}
    DateTime DateBuy { get; set;}
    ...
    }

【问题讨论】:

  • 你能发布更多细节吗,VMDataProperty 是什么,一个集合?

标签: silverlight xaml templatebinding


【解决方案1】:

在我看来,您应该设置“A”的 DataContext 而不是它的 ItemsSource。

【讨论】:

  • 这行得通:,
  • 如果它对你有用,你能把它作为接受的答案吗?
猜你喜欢
  • 2012-01-28
  • 1970-01-01
  • 2021-05-09
  • 2020-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多