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 :

User Control ListBoxItem


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 331
    Par défaut User Control ListBoxItem
    Bonjour,

    je débute en WPF et je m'arrache les cheveux

    J'essaye de faire un truc relativement simple :

    Dans mon application WPF, j'ai une listBox.
    Je créais à la volé, dans le codebehind, les listboxitem
    et ces listboxitem, j'aimerai que ce soit des userControl (car je veux afficher joliement le toolTip).

    Avez vous une idée de la façon dont je dois procéder ?

    Merci d'avance

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 331
    Par défaut
    En fait, pour l'instant, j'ai ceci dans mon WPF principal:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <Grid>
            <ListBox>
                <uc:CustomListBoxItem Title="my list 1" CustomToolTip="test 1"/>
                <uc:CustomListBoxItem Title="my list  2" CustomToolTip="test 2"/>
                <uc:CustomListBoxItem Title="my list  3" CustomToolTip="test 3" />
                <uc:CustomListBoxItem Title="my list  4" CustomToolTip="test 4"/>
            </ListBox>
    </Grid>
    et mon UserControl ressemble à cela :
    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
     
    <UserControl x:Class="WpfApplication1.CustomListBoxItem"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Name="myCustomListBoxItem">
        <Grid>
            <ListBoxItem Content="{Binding ElementName=myCustomListBoxItem, Path=Title}">
                <ListBoxItem.ToolTip>
                    <StackPanel Background="Honeydew" Height="200" Width="200">
                        <StackPanel Background="BurlyWood" Height="30" Width="200" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" >
                            <TextBlock FontFamily="Aharoni" 
                                       FontSize="24" FontWeight="Bold" 
                                       Foreground="Black" TextWrapping="Wrap" 
                                       VerticalAlignment="Top" Height="30" 
                                       HorizontalAlignment="Right" Width="143"
                                        >
                                <Run FontFamily="Andalus" FontSize="18" FontWeight="Normal" Text="{Binding ElementName=myCustomListBoxItem, Path=CustomToolTip}"/>
     
                            </TextBlock>
                        </StackPanel>
     
                        <StackPanel Width="200" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" >
                            <TextBlock TextWrapping="Wrap" Foreground="#FFF9F4F4" TextAlignment="Center" Background="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top" Width="181" Height="98">
                              <Run FontFamily="Verdana" FontSize="11" FontWeight="Normal" Foreground="#FF151514"
                                   Text="Format your tip the way you want and put any image, text or other controls on it.
                                   Also, you can add more controls in this tip the way you want to format it."/>
                            </TextBlock>
                        </StackPanel>
                    </StackPanel>
                </ListBoxItem.ToolTip>
     
            </ListBoxItem>
        </Grid>
    </UserControl>
    Voici le code behind de mon user control
    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
     
            public string Title
            {
                get { return (string)GetValue(TextProperty); }
                set { SetValue(TextProperty, value); }
            }
     
            // Using a DependencyProperty as the backing store for Title.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty TextProperty =
                DependencyProperty.Register("Title", typeof(string), typeof(CustomListBoxItem));
     
            public string CustomToolTip
            {
                get { return (string)GetValue(CustomToolTipProperty);}
                set { SetValue(CustomToolTipProperty, value); }
            }
     
            // Using a DependencyProperty as the backing store for Title.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty CustomToolTipProperty =
                DependencyProperty.Register("CustomToolTip", typeof(string), typeof(Control));

Discussions similaires

  1. [C#]liste de choix dans une propriété d'un user control
    Par LeDeveloppeurDotNet dans le forum Windows Forms
    Réponses: 2
    Dernier message: 07/10/2005, 12h41
  2. [C#] User control
    Par Verboz dans le forum ASP.NET
    Réponses: 4
    Dernier message: 27/04/2005, 22h46
  3. [C#] User Control dynamic
    Par Erakis dans le forum ASP.NET
    Réponses: 10
    Dernier message: 21/10/2004, 18h54
  4. [C#] DateTimePicker web user control
    Par titi29 dans le forum ASP.NET
    Réponses: 8
    Dernier message: 29/06/2004, 18h38
  5. [VB.NET] Provoquer le rechargement d'un user control..
    Par didoboy dans le forum ASP.NET
    Réponses: 7
    Dernier message: 30/04/2004, 14h17

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