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 :

[ToolTips] probleme de binding


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    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 [ToolTips] probleme de binding
    bonjour

    un petit problème étonnant que j'ai rencontré
    quand je fais sur une fenêtre
    Code xaml : 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
     
     <StackPanel Height="136"
                        Margin="256,0,168,44"
                        VerticalAlignment="Bottom">
                <TextBlock Text="Information functions"
                           FontWeight="Bold" />
                <StackPanel Orientation="Horizontal">
                    <TextBlock x:Name="base2"
                               Width="60"
                               Text="Space :"
                               FontWeight="Bold" />
                    <TextBlock Text="Panel functions open/close" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Width="{Binding ActualWidth, ElementName=base2}"
                               Text="F1 :"
                               FontWeight="Bold" />
                    <TextBlock Text="Mouse mode On/Off" />
                </StackPanel>
            </StackPanel>

    le binding sur le width marche tres bien

    si je colle le tout dans un tool tips
    ca ne marche plus
    Code xaml : 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
     
     <Rectangle Fill="#FFF4F4F5"
                       HorizontalAlignment="Left"
                       Height="40"
                       Margin="40,0,0,84"
                       Stroke="Black"
                       VerticalAlignment="Bottom"
                       Width="104">
                <Rectangle.ToolTip>
                    <StackPanel>
                        <TextBlock Text="Information functions"
                                   FontWeight="Bold" />
                        <StackPanel Orientation="Horizontal">
                            <TextBlock x:Name="base"
                                       Width="60"
                                       Text="Space :"
                                       FontWeight="Bold" />
                            <TextBlock Text="Panel functions open/close" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="F1 :"
                                       FontWeight="Bold"
                                       Width="{Binding ActualWidth, ElementName=base}"/>
                            <TextBlock Text="Mouse mode On/Off" />
                        </StackPanel>
                    </StackPanel>
                </Rectangle.ToolTip>
            </Rectangle>

    bon j'ai bien trouvé une solution en collant
    Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
      <StackPanel Orientation="Horizontal">
                <TextBlock Width="{Binding Parent.Parent.Children[1].Children[0].Width, 
    										   RelativeSource={RelativeSource Self}}"
                           Text="toto"
                           FontWeight="Bold" />
                <TextBlock  Text="titi" />
            </StackPanel>

    mais franchement c'est pas super sexy
    quelqu'un a une idée plus sympa ?

    merci

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Je vois pas trop d'où vient le problème, mais pourquoi utiliser des StackPanels ? C'est clairement une Grid qu'il te faut...

    Code XAML : 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
            <Rectangle Fill="#FFF4F4F5"
                       HorizontalAlignment="Left"
                       Height="40"
                       Margin="40,0,0,84"
                       Stroke="Black"
                       VerticalAlignment="Bottom"
                       Width="104">
                <Rectangle.ToolTip>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="Information functions" FontWeight="Bold" />
                        <TextBlock Grid.Row="1" Grid.Column="0" Text="Space :" FontWeight="Bold" />
                        <TextBlock Grid.Row="1" Grid.Column="1" Text="Panel functions open/close" />
                        <TextBlock Grid.Row="2" Grid.Column="0" Text="F1 :" FontWeight="Bold" />
                        <TextBlock Grid.Row="2" Grid.Column="1" Text="Mouse mode On/Off" />
                    </Grid>
                </Rectangle.ToolTip>
            </Rectangle>

  3. #3
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Si tu trouves que c'est trop lourd de déclarer les lignes et colonnes de la Grid, tu peux utiliser ça :

    Code XAML : Sélectionner tout - Visualiser dans une fenêtre à part
    <my:SimpleGrid Rows="*,*,*" Columns="60,*">

  4. #4
    Membre éclairé Avatar de koyot3
    Inscrit en
    Avril 2007
    Messages
    693
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 693
    Par défaut
    Salut ikeas,

    Je crois que le binding sur un élément dans un tootip n'est pas fonctionnel car il n'est pas contenu dans l'arbre visuel (ou logique) de ta page et donc le ElementName n'a pas la bonne référence.

    C'est d'ailleurs un peu pareil avec le menu contextuel, qui est une sorte de surcouche visuel sur ta page...

    Par contre si tu redéfinis ton propre ControlTemplate de ton tooltip, ça fonctionne (bon c'est plus vraiment un tooltip mais )

    edit : j'ai regardé par curiosité et si pas exemple tu connais la taille de ton premier stackpanel avant l'ouverture du tooltip, tu peux la stocker dans le Tag de ton rectangle et le récupérer ensuite

    Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     <ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Self}}">
    ...
     <TextBlock Text="F1 :"                                              FontWeight="Bold" Width="{Binding Tag}"/>

    Bon c'est pas non plus très sexy

  5. #5
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Quelques infos supplémentaires sur le problème de binding :
    http://agsmith.wordpress.com/2008/07...g-a-namescope/

  6. #6
    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
    merci tous pour vos solutions sympa
    moi j'avais trouvé ca le truc de andrew smith assez sympa d'ailleurs
    (qui permet de comprendre le fonctionnel du tooltip en passant lol)

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

Discussions similaires

  1. Problème avec BIND
    Par Titam dans le forum Réseau
    Réponses: 2
    Dernier message: 16/10/2006, 12h40
  2. Problème avec bind!!!
    Par ouakammathieu dans le forum Réseau
    Réponses: 4
    Dernier message: 14/05/2006, 23h46
  3. probleme de bind variable
    Par elbrujo2323 dans le forum Oracle
    Réponses: 7
    Dernier message: 22/02/2006, 13h49
  4. [wxPython] Problème de 'Bind'
    Par Mr Hyde dans le forum wxPython
    Réponses: 6
    Dernier message: 25/08/2005, 16h53
  5. Problème avec bind
    Par jaabouc dans le forum Réseau
    Réponses: 5
    Dernier message: 12/06/2005, 14h32

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