Meilleur auteur de réponses
Problème de Binding entre les UserControls

Question
-
Bonjour,
Avant de commencer j'explique la hiérarchie de mon projet:
- ucMainView (DataContext = mainViewModel) x:Name="topLevel"
- ucRibbonMenu (DataContext = mainViewModel.CommandShow) x:Name="myRibbonMenu"
- ucToolBar (DataContext = mainViewModel ) x:Name="myToolBar"
- ucTabControl (ItemSource= mainViewModel.maListObservableCollection) x:Name="" et j'ai utilisé avec un DataTemple pour définir les relations
- ucTvaDetailView (DataContext = tvaDetailViewModel) x:Name=""
- ucTvaListView (dataContext = tvaListViewModel) x:Name=""
pour afficher Un TabItem j'utilise mon menu est ça marche bien,
j'ai ajouter un bouton dans ucTvaDetailView en clinquant sur ce dernier on doit ouvrir ou réouvrir ucTvaListViewon,
dans mon code j'ai essayer de récupérer le DataContext de MainView ou bien du RibbonMenu afin de lancer la command, mais en fin de compte ça marche pas:
<StackPanel Grid.Row="0" Grid.Column="1" Margin="10,6,10,3" Width="Auto" Height="Auto"
Orientation="Horizontal"
HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBox Width="120" Text="{Binding Path=TVA}"/>
<Button Width="15" Height="22"
DataContext="{Binding Path=DataContext, ElementName=topLevel}"
Command="{Binding Path=CommandsShow.ShowTvaListCommand}">
<Image Stretch="Fill"
Source="/ITSProject.UIProjectV4;component/Images/TaskForAll/List.jpg" />
</Button>
</StackPanel >comment je fais pour accéder à la command ShowTvaListCommand dans CommandShow ?
sinon y a t'il une autre solution ?
merci pour votre aide,
Réponses
-
Bonjour,
en fin de compte çà marche, voici ce que je viens de faire tout à l'heur:
Code :1
2
3
4
5
6
7
8<Button Width="15" Height="22" Command="{Binding Path=DataContext.CommandsShow.ShowTvaListCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=my:MainWindowView, AncestorLevel=1}}" > <Image Stretch="Fill" Source="/ITSProject.UIProjectV4;component/Images/TaskForAll/List.jpg" /> </Button>
- Dans Source -> RelativeSource-> FindAncestor-> dans une liste j'ai choisi: ucMainView (avec AncestorLevel=1)
- Dans Chemin d'accées -> j'ai choisi la propriété "DataContext" du "ucMainView" bien sur,
- Dans le code source j'ai ajoutée le chemin de ma command Path=DataContext.CommandsShow.ShowTvaListCommand
- et voilà ça marche très bien
maintenant je vais m'orienter vers le passage paramètres et le retour d’appel,avez vous un bon lien?
merci à vous,
Thanks- Marqué comme réponse Ishak23 jeudi 9 juin 2011 11:24
Toutes les réponses
-
-
Bonjour,
en fin de compte çà marche, voici ce que je viens de faire tout à l'heur:
Code :1
2
3
4
5
6
7
8<Button Width="15" Height="22" Command="{Binding Path=DataContext.CommandsShow.ShowTvaListCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=my:MainWindowView, AncestorLevel=1}}" > <Image Stretch="Fill" Source="/ITSProject.UIProjectV4;component/Images/TaskForAll/List.jpg" /> </Button>
- Dans Source -> RelativeSource-> FindAncestor-> dans une liste j'ai choisi: ucMainView (avec AncestorLevel=1)
- Dans Chemin d'accées -> j'ai choisi la propriété "DataContext" du "ucMainView" bien sur,
- Dans le code source j'ai ajoutée le chemin de ma command Path=DataContext.CommandsShow.ShowTvaListCommand
- et voilà ça marche très bien
maintenant je vais m'orienter vers le passage paramètres et le retour d’appel,avez vous un bon lien?
merci à vous,
Thanks- Marqué comme réponse Ishak23 jeudi 9 juin 2011 11:24