IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

Binding FindAncestor: source not found


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2007
    Messages
    54
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Septembre 2007
    Messages : 54
    Par défaut Binding FindAncestor: source not found
    Bonjour à tous,

    Petit problème avec mon binding. J'ai une liste qui contient des éléments et un contextmenu (woua ). Ces éléments ont un champ 'DigitalFormat' (bool) qui doit être bindé sur un la propriété "IsChecked" du menuitem de mon contextmenu.

    Le problème c'est que lorsque j'accède à mon contextmenu, il semblerait qu'il ne trouve pas mon champ 'DigitalFormat'. Voici l'erreur que j'aperçoit en output:

    System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ListViewItem', AncestorLevel='1''. BindingExpressionath=DigitalFormat; DataItem=null; target element is 'MenuItem' (Name='cmSetDigitalFormat'); target property is 'IsChecked' (type 'Boolean')
    Alors j'ai essayé une première fois de binder avec ElementName=lvCollection, Path=SelectedItem.DigitalFormat ... et maintenant j'essaye avec FindAncestor, mais rien ne fait, il n'arrive pas à lier les deux visiblement.

    Si qqn a un éclaircissement


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
                    <ListView Name="lvCollection" 
                              Margin="12,0,12,12"
                              Height="213"
                              VerticalAlignment="Bottom"
                              IsSynchronizedWithCurrentItem="True"
                              ItemsSource="{Binding ElementName=lvSeriesCollection, Path=SelectedItem.Albums}"
                              MouseDoubleClick="lvCollection_MouseDoubleClick">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Number" Width="50" DisplayMemberBinding="{Binding Path=Album.Number}"/>
                                <GridViewColumn Header="Digital Format" Width="80" DisplayMemberBinding="{Binding Path=DigitalFormat}"/>
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Name="cmSetDigitalFormat" 
                                          Header="Set as Digital Format"  
                                          IsCheckable="True" IsChecked="{Binding Path=DigitalFormat, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}"
                                          Click="cmSetDigitalFormat_Click"/>
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 562
    Par défaut
    je me demande si il faut pas mettre le context menu dans le item template
    ou s'il faut pas mettre l'information de binding sur le selecteditem

  3. #3
    Membre Expert
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 562
    Par défaut
    ecoute je viens de tesret ton code avec une resource a moi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
        <Window.Resources>
            <Local:PersonneCollection x:Name="Personnes" x:Key="Personnes" MaxSize="10"/>
        </Window.Resources>
        <Grid>
            <ListView Name="lvCollection" 
                              Margin="12,0,12,12"
                              Height="213"
                              VerticalAlignment="Bottom"
                              IsSynchronizedWithCurrentItem="True"
                              ItemsSource="{StaticResource Personnes}"
                              MouseDoubleClick="lvCollection_MouseDoubleClick">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Nom" Width="50" DisplayMemberBinding="{Binding Path=Nom}"/>
                        <GridViewColumn Header="Prenom" Width="80" DisplayMemberBinding="{Binding Path=Prenom}"/>
                        <GridViewColumn Header="Digital" Width="80" DisplayMemberBinding="{Binding Path=DigitalFormat}"/>
                    </GridView>
                </ListView.View>
                <ListView.ContextMenu>
                    <ContextMenu>
                        <MenuItem Name="cmSetDigitalFormat" 
                            Header="Set as Digital Format"  
                            IsCheckable="True" 
                            IsChecked="{Binding Path=DigitalFormat, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}"
                            Click="cmSetDigitalFormat_Click"/>
                    </ContextMenu>
                </ListView.ContextMenu>
            </ListView>
    pour les personnes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
     
        #region Personne
        //----------------------------------------------------------------------------
        public class Personne: INotifyPropertyChanged
        {
            //----------------------------------------------------------------------------
            private string _Nom = "";
            public string Nom
            {
                get { return _Nom; }
                set 
                { 
                    _Nom = value;
                    OnPropertyChanged("Nom");
                }
            }
            //----------------------------------------------------------------------------
            private string _Prenom = "";
            public string Prenom
            {
                get { return _Prenom; }
                set 
                { 
                    _Prenom = value;
                    OnPropertyChanged("Prenom");
                }
            }
            //----------------------------------------------------------------------------
            private int _Age = 0;
            public int Age
            {
                get { return _Age; }
                set 
                { 
                    _Age = value;
                    OnPropertyChanged("Age");
                }
            }
            //----------------------------------------------------------------------------
            private Color _Color = Colors.Transparent;
            public Color Color
            {
                get { return _Color; }
                set 
                { 
                    _Color = value;
                    OnPropertyChanged("Color");
                }
            }
            //----------------------------------------------------------------------------
            private eLevel _Level = eLevel.None;
            public eLevel Level
            {
                get { return _Level; }
                set
                {
                    _Level = value;
                    OnPropertyChanged("Level");
                }
            }
            //----------------------------------------------------------------------------
            private bool _DigitalFormat = false;
            public bool DigitalFormat
            {
                get { return _DigitalFormat; }
                set
                {
                    _DigitalFormat = value;
                    OnPropertyChanged("DigitalFormat");
                }
            }
            //----------------------------------------------------------------------------
            #region INotifyPropertyChanged Membres
            //----------------------------------------------------------------------------
            public event PropertyChangedEventHandler PropertyChanged;
            private void OnPropertyChanged(string propertyName)
            {
                OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
            }
            private void OnPropertyChanged(PropertyChangedEventArgs e)
            {
                if (PropertyChanged != null) PropertyChanged(this, e);
            }
            //----------------------------------------------------------------------------
            #endregion
            //----------------------------------------------------------------------------
        }
    et la collection
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
        public class PersonneCollection : ObservableCollection<Personne>
        {}
    et voici le code de modification
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
           private void cmSetDigitalFormat_Click(object sender, RoutedEventArgs e)
            {
                (this.lvCollection.SelectedItem as Personne).DigitalFormat = (sender as MenuItem).IsChecked;
            }
    et ca marche (j'ai rajoute la column pour voir l'etat du digital

  4. #4
    Membre Expert
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 562
    Par défaut
    bon je rectifie ce que je t'ai dit
    a mettre dans les resources
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    <ContextMenu x:Key="RowContextMenu"
              MenuItem.Click="OnMenuItemClick"
              ItemsSource="{Binding MenuOptions}">
                <ContextMenu.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                       <Setter Property="Header" Value="{Binding}" />
                    </Style>
                </ContextMenu.ItemContainerStyle>
                <MenuItem Name="cmSetDigitalFormat" 
                            Header="{Binding Nom, Converter={StaticResource DummyConverter}}"  
                            IsCheckable="True" 
                            IsChecked="{Binding Path=SelectedItem.DigitalFormat}"
                            Click="cmSetDigitalFormat_Click"/>
            </ContextMenu>
    et le code de la listview
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
            <ListView Name="lvCollection" 
                              Margin="12,0,12,12"
                              Height="213"
                              VerticalAlignment="Bottom"
                              IsSynchronizedWithCurrentItem="True"
                              ItemsSource="{StaticResource Personnes}"
                              MouseDoubleClick="lvCollection_MouseDoubleClick">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Nom" Width="50" DisplayMemberBinding="{Binding Path=Nom}"/>
                        <GridViewColumn Header="Prenom" Width="80" DisplayMemberBinding="{Binding Path=Prenom}"/>
                        <GridViewColumn Header="Digital" Width="80" DisplayMemberBinding="{Binding Path=DigitalFormat}"/>
                    </GridView>
                </ListView.View>
                <ListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="ContextMenu" Value="{StaticResource RowContextMenu}" />
                    </Style>
                </ListView.ItemContainerStyle>

  5. #5
    Membre confirmé
    Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2007
    Messages
    54
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Septembre 2007
    Messages : 54
    Par défaut
    Merci pour l'aide, je vais tester tout ça !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Debug : Source Not Found
    Par gargantua dans le forum Eclipse Java
    Réponses: 5
    Dernier message: 10/09/2009, 10h54
  2. "Source not found" en mode Debug
    Par gabier dans le forum Eclipse Java
    Réponses: 5
    Dernier message: 12/03/2008, 12h31
  3. Bloqué sur Eclipse Java: "source not found"
    Par EnRadeSurEclipse dans le forum Eclipse Java
    Réponses: 6
    Dernier message: 17/12/2007, 09h16
  4. Source not found - Edit source lookup path
    Par Widiwi dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 16/08/2007, 15h27
  5. Debug : source not found
    Par polo54 dans le forum Eclipse Java
    Réponses: 4
    Dernier message: 16/10/2006, 15h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo