Je crée une propriété attachée. Ma classe attachée est helper:FocusDetail
et a 2 propriétés. seconde propriété DetailBody
le type est l'objet. J'utilise cette propriété sur les éléments de commandeDéclaration de propriété jointe en xaml
<ItemsControl ItemsSource="{Binding Riches}" BorderThickness="0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding TextInfo}"
helper:FocusDetail.DetailTitle="{StaticResource strTitle}"
helper:FocusDetail.DetailBody="{Binding Description}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
qui fonctionne avec succès
Je change la valeur attachée comme celui-ci
<DataTemplate>
<TextBox Text="{Binding TextInfo}"
helper:FocusDetail.DetailTitle="{StaticResource strTitle}">
<helper:FocusDetail.DetailBody>
<Binding Path="Description"/>
</helper:FocusDetail.DetailBody>
</TextBox>
</DataTemplate>
Ce travail est je change de nouveau
<DataTemplate>
<TextBox Text="{Binding TextInfo}"
helper:FocusDetail.DetailTitle="{StaticResource strTitle}"
>
<helper:FocusDetail.DetailBody>
<TextBlock Text="Some static text"></TextBlock>
</helper:FocusDetail.DetailBody>
</TextBox>
Cela fonctionne. Mon dernier changement est ici
<DataTemplate>
<TextBox Text="{Binding TextInfo}"
helper:FocusDetail.DetailTitle="{StaticResource strTitle}">
<helper:FocusDetail.DetailBody>
<TextBlock Text="{Binding Description}"></TextBlock>
</helper:FocusDetail.DetailBody>
</TextBox>
</DataTemplate>
Ce n'est pas un travail. Le bloc de texte est vide.
Je change
<TextBlock Text="{Binding Description}"></TextBlock>
à
<TextBlock Text="{Binding }"></TextBlock>
.
Mais textblock renvoie le type Window DataContext. Vous avez déjà quitté l'itération Itemscontrol.
Pourquoi la liaison est-elle incorrecte? Comment déclarer une propriété jointe comme le dernier code?
J'ai besoin de la propriété jointe contient des contrôles d'arborescence visuelle.