je tente de factoriser comme XAML en introduisant nouveau contrôle utilisateur:Refactor Code XAML avec une liaison
<Window ...>
<ComboBox ItemsSource="{Binding Greetings}" />
</Window>
Après avoir ajouté un contrôle je
ControlA XAML:
<UserControl ...>
<ComboBox ItemsSource="{Binding Items}" />
</UserControl>
ControlA C#:
public static readonly DependencyProperty ItemsProperty =
WpfUtils.Property<IEnumerable, ControlA>("Items");
public IEnumerable Items { get; set; }
Nouveau Fenêtre XAML:
<Window ...>
<uc:ControlA Items="{Binding Greetings}" />
</Window>
Après cela, je ne vois rien dans ComboBox. Quel est le problème ici?
J'ai eu this.DataContext = this; dans les contrôles code-behind. Ajout de Racine et nouvelle ComboBox comme vous l'avez suggéré, mais obtenez toujours des cases vides. – alex2k8
Gotcha, définissant 'this.DataContext = this;' écrasé le contexte de la fenêtre principale. – alex2k8