C# 访问ItemTemplate Silverlight中的模板化列表框
我正在silverlight中创建一个模板控件,它基本上是一个列表框,列表框中的每个项目都有一个组合框 我试图将combobox选项作为依赖项属性存储在主控件中,然后访问每个项上的控件以将combobox的ItemsSource绑定到此依赖项属性,但我似乎无法获得正确的绑定,无论是查看单个项还是主窗口视图模型。下面是我目前拥有的 控制C# 访问ItemTemplate Silverlight中的模板化列表框,c#,xaml,templates,mvvm,silverlight-5.0,C#,Xaml,Templates,Mvvm,Silverlight 5.0,我正在silverlight中创建一个模板控件,它基本上是一个列表框,列表框中的每个项目都有一个组合框 我试图将combobox选项作为依赖项属性存储在主控件中,然后访问每个项上的控件以将combobox的ItemsSource绑定到此依赖项属性,但我似乎无法获得正确的绑定,无论是查看单个项还是主窗口视图模型。下面是我目前拥有的 控制 好的,现在解决了,需要将ListBox的DataContext绑定到模板化的父对象 DataContext="{Binding RelativeSource={R
好的,现在解决了,需要将ListBox的DataContext绑定到模板化的父对象
DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
然后combobox项源的相对源绑定工作
ItemsSource="{Binding DataContext.DropDownOptions, RelativeSource={RelativeSource AncestorType=telerik:RadListBox}}"
ItemsSource="{Binding DataContext.DropDownOptions, ElementName=GroupList}"
ItemsSource="{Binding DataContext.DropDownOptions, RelativeSource={RelativeSource AncestorType=telerik:RadListBox}}"
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource TemplatedParent}}"
DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
ItemsSource="{Binding DataContext.DropDownOptions, RelativeSource={RelativeSource AncestorType=telerik:RadListBox}}"