Я играю с Infragistics xamDataGrid. Я хотел бы отобразить в поле «Field» (= Cell) пользовательский UserControl и иметь для него DataContext поля. Как-то DataContext всегда нуль :-)DataBinding UserControl через ControlTemplate
Вот XAML:
<UserControl.Resources>
<Style x:Key="MyTestUserControl" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<myUC:MyTestUserControl
DataContext="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=Value}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="TextBoxField" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<TextBox Text="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=Value}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
DataContext для TextBoxField работает отлично, но DataContext для MyUserControl нет.
Некоторые более XAML, где я определяю поля:
<igDP:UnboundField BindingPath="SimpleTestStringToDisplay" Label="UnboundField">
<igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource TextBoxField}" />
</igDP:Field.Settings>
</igDP:UnboundField>
<igDP:UnboundField BindingPath="MyUserControlViewModel"
Label="UnboundField (UserControl)">
<igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource MyTestUserControl}" />
</igDP:Field.Settings>
</igDP:UnboundField>
Кто-нибудь есть идея, что я делаю не так?
Спасибо!
Приветствия, Джозеф
EDIT: я пытался что-то вроде этого, но безуспешно:
<myUC:MyUserControl DataContext="{TemplateBinding DataContext}" />
Спасибо за ответ. Мне на самом деле не нужно было что-то вставлять в UserControl .. он просто «наследует» DataContext от UnboundField, если его правильно объявит ;-) –