none
Problème de Binding entre les UserControls RRS feed

  • 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,

     

    mercredi 8 juin 2011 17:55

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>
    j'ai utilisé l'explorateur de propriétés de Visual Studio afin d'aller à DataContext du ucMainView, Dans la propriété Command:
    • 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
    jeudi 9 juin 2011 11:17

Toutes les réponses

  • Bonjour,

    si vous être besoin de plus de codes je vous en ajoute,

    merci, ;)

    jeudi 9 juin 2011 10:30
  • 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>
    j'ai utilisé l'explorateur de propriétés de Visual Studio afin d'aller à DataContext du ucMainView, Dans la propriété Command:
    • 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
    jeudi 9 juin 2011 11:17