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 :

listbox façon "spinning wheel"


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 25
    Par défaut listbox façon "spinning wheel"
    Bonsoir à tous,

    Dans mon projet, je cherche à créer une listbox où les items seraient disposés de manière semi circulaire genre "lecteur deezer plein ecran" pour ceux qui connaissent.
    Le seul bout de code que j'ai trouvé se trouve là :
    http://www.wintellect.com/CS/blogs/j...lverlight.aspx
    Il s'agit du code avec les noms/prénoms.
    Mais si je l'applique à mon code j'ai une exception
    "VisualTree de ItemsPanelTemplate doit être un seul élément"
    Quelqu'un aurait-il un idée voir une autre piste pour créer une listbox façon "spinning wheel"?

    Merci d'avance!!!

  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 : 43
    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
    Citation Envoyé par brad63 Voir le message
    Mais si je l'applique à mon code j'ai une exeption "VisualTree de ItemsPanelTemplate doit être un seul élément"
    Tu as dû te planter quelque part... fais voir ton code

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 25
    Par défaut
    Bonjour Tomlev,

    voici les 2 bouts de code :

    le xaml :
    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
    <Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:custom="clr-namespace:TemplatedListBoxDemo"
        Title="Window1" Height="300" Width="300">
        <Grid>
            <TabControl Canvas.Left="420" Canvas.Top="95" Height="275.824" Name="tabControl1" Width="395.111" >
                <TabItem Header="Traditional Layout">
                    <ListBox Canvas.Left="540" Canvas.Top="200" Height="215" Name="listBox2" Width="295" >
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <custom:RadialPanel Radius="150" ItemAlignment="Left" ItemOrientation="Rotated" />
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <TextBlock Text="Jeff Prosise" Foreground="Red" />
    					<TextBlock Text="Jeffrey Richter" Foreground="Orange" />
    					<TextBlock Text="John Robbins" Foreground="Green" />
    					<TextBlock Text="Steve Porter" Foreground="Blue" />
    					<TextBlock Text="Keith Rome" Foreground="Blue" />
    					<TextBlock Text="Rik Robinson" Foreground="Darkblue" />
    					<TextBlock Text="Andy Hopper" Foreground="Purple" />
    					<TextBlock Text="Sergio Lascio" Foreground="#ff80c0" />
     
    					<TextBlock Text="Jeff Prosise" Foreground="Red" />
    					<TextBlock Text="Jeffrey Richter" Foreground="Orange" />
    					<TextBlock Text="John Robbins" Foreground="Green" />
    					<TextBlock Text="Steve Porter" Foreground="Blue" />
    					<TextBlock Text="Keith Rome" Foreground="Blue" />
    					<TextBlock Text="Rik Robinson" Foreground="Darkblue" />
    					<TextBlock Text="Andy Hopper" Foreground="Purple" />
    					<TextBlock Text="Sergio Lascio" Foreground="#ff80c0" />
     
    					<TextBlock Text="Jeff Prosise" Foreground="Red" />
    					<TextBlock Text="Jeffrey Richter" Foreground="Orange" />
    					<TextBlock Text="John Robbins" Foreground="Green" />
    					<TextBlock Text="Steve Porter" Foreground="Blue" />
    					<TextBlock Text="Keith Rome" Foreground="Blue" />
    					<TextBlock Text="Rik Robinson" Foreground="Darkblue" />
    					<TextBlock Text="Andy Hopper" Foreground="Purple" />
    					<TextBlock Text="Sergio Lascio" Foreground="#ff80c0" />
     
    					<TextBlock Text="Jeff Prosise" Foreground="Red" />
    					<TextBlock Text="Jeffrey Richter" Foreground="Orange" />
    					<TextBlock Text="John Robbins" Foreground="Green" />
    					<TextBlock Text="Steve Porter" Foreground="Blue" />
    					<TextBlock Text="Keith Rome" Foreground="Blue" />
    					<TextBlock Text="Rik Robinson" Foreground="Darkblue" />
    					<TextBlock Text="Andy Hopper" Foreground="Purple" />
    					<TextBlock Text="Sergio Lascio" Foreground="#ff80c0" />
     
                        </ListBox>
     
                </TabItem>
     
     
            </TabControl>
        </Grid>
    </Window>
    et le cs qui va avec :

    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
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
     
    namespace TemplatedListBoxDemo
    {
        public class RadialPanel : Panel
        {
            // Dependency properties
            public static readonly DependencyProperty RadiusProperty;
            public static readonly DependencyProperty ItemAlignmentProperty;
            public static readonly DependencyProperty ItemOrientationProperty;
     
            public double Radius
            {
                get { return (double)GetValue(RadiusProperty); }
                set { SetValue(RadiusProperty, value); }
            }
     
            public ItemAlignmentOptions ItemAlignment
            {
                get { return (ItemAlignmentOptions)GetValue(ItemAlignmentProperty); }
                set { SetValue(ItemAlignmentProperty, value); }
            }
     
            public ItemOrientationOptions ItemOrientation
            {
                get { return (ItemOrientationOptions)GetValue(ItemOrientationProperty); }
                set { SetValue(ItemOrientationProperty, value); }
            }
     
            private static void RadiusChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
            {
                RadialPanel panel = (RadialPanel)sender;
                panel.Refresh(new Size(panel.Width, panel.Height));
            }
     
            private static void ItemAlignmentChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
            {
                RadialPanel panel = (RadialPanel)sender;
                panel.Refresh(new Size(panel.Width, panel.Height));
            }
     
            private static void ItemOrientationChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
            {
                RadialPanel panel = (RadialPanel)sender;
                panel.Refresh(new Size(panel.Width, panel.Height));
            }
     
            // Static constructor
            static RadialPanel()
            {
                RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(RadialPanel),
                    new PropertyMetadata(new PropertyChangedCallback(RadialPanel.RadiusChanged)));
                ItemAlignmentProperty = DependencyProperty.Register("ItemAlignment", typeof(ItemAlignmentOptions), typeof(RadialPanel),
                    new PropertyMetadata(new PropertyChangedCallback(RadialPanel.ItemAlignmentChanged)));
                ItemOrientationProperty = DependencyProperty.Register("ItemOrientation", typeof(ItemOrientationOptions), typeof(RadialPanel),
                    new PropertyMetadata(new PropertyChangedCallback(RadialPanel.ItemOrientationChanged)));
            }
     
            // Overrides
            protected override Size MeasureOverride(Size availableSize)
            {
                Size max = new Size(0.0, 0.0);
     
                // Call Measure on each child and record the maximum
                // width and height of the child elements
                foreach (UIElement element in this.Children)
                {
                    element.Measure(availableSize);
                    max.Width = Math.Max(max.Width, element.DesiredSize.Width);
                    max.Height = Math.Max(max.Height, element.DesiredSize.Height);
                }
     
                // Compute our own desired size, taking into account the fact
                // that availableSize could specify infinite widths and heights
                // (which are not valid return values)
                double width = double.IsPositiveInfinity(availableSize.Width) ?
                    (2.0 * this.Radius) + max.Width : availableSize.Width;
                double height = double.IsPositiveInfinity(availableSize.Height) ?
                    (2.0 * this.Radius) + max.Height : availableSize.Height;
     
                // Return our desired size
                return new Size(width, height);
            }
     
            protected override Size ArrangeOverride(Size finalSize)
            {
                // Size and position the child elements
                this.Refresh(finalSize);
                return finalSize;
            }
     
            // Helper methods
            private void Refresh(Size size)
            {
                int i = 0;
                double inc = 360.0 / this.Children.Count;
     
                foreach (FrameworkElement element in this.Children)
                {
                    double width = 0.0;
                    double height = 0.0;
     
                    switch (this.ItemAlignment)
                    {
                        case ItemAlignmentOptions.Left:
                            width = 0.0;
                            height = 0.0;
                            break;
     
                        case ItemAlignmentOptions.Center:
                            width = element.DesiredSize.Width / 2.0;
                            height = element.DesiredSize.Height / 2.0;
                            break;
     
                        case ItemAlignmentOptions.Right:
                            width = element.DesiredSize.Width;
                            height = element.DesiredSize.Height;
                            break;
                    }
     
                    double angle = inc * i++;
     
                    if (this.ItemOrientation == ItemOrientationOptions.Rotated)
                    {
                        RotateTransform transform = new RotateTransform();
                        transform.CenterX = width;
                        transform.CenterY = height;
                        transform.Angle = angle;
                        element.RenderTransform = transform;
                    }
     
                    double x = this.Radius * Math.Cos((Math.PI * angle) / 180.0);
                    double y = this.Radius * Math.Sin((Math.PI * angle) / 180.0);
     
                    element.Arrange(new Rect((x + (size.Width / 2.0)) - width,
                        (y + (size.Height / 2.0)) - height,
                        element.DesiredSize.Width,
                        element.DesiredSize.Height));
                }
            }
        }
     
        // Enums
        public enum ItemAlignmentOptions
        {
            Left, Center, Right
        }
     
        public enum ItemOrientationOptions
        {
            Upright, Rotated
        }
    }
    Ce qui est bizarre cest que quand je rajoute le code xaml je vois pendant une seconde la roue avec les noms en cercle puis j'ai le message

    VisualTree de ItemsPanelTemplate doit être un seul élément.
    à System.Windows.Controls.ItemsPresenter.OnApplyTemplate()
    à System.Windows.FrameworkElement.ApplyTemplate()
    à System.Windows.Controls.ScrollContentPresenter.HookupScrollingComponents()
    à System.Windows.Controls.ScrollContentPresenter.OnApplyTemplate()
    à System.Windows.FrameworkElement.ApplyTemplate()
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Border.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Control.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
    à System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Border.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Control.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
    à System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
    à System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Border.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Border.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Border.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Grid.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Control.MeasureOverride(Size constraint)
    à MS.Internal.WindowControl.DesignTimeWindow.MeasureOverride(Size availableSize)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à MS.Internal.Designer.SimpleViewManager.DesignerBackground.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
    à Microsoft.Windows.Design.Interaction.DesignerView.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à MS.Internal.Designer.Viewport.MeasureOverride(Size availableSize)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
    à System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
    à System.Windows.Controls.Grid.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Grid.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
    à System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Controls.Control.MeasureOverride(Size constraint)
    à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    à System.Windows.UIElement.Measure(Size availableSize)
    à System.Windows.Interop.HwndSource.SetLayoutSize()
    à System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
    à System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
    à MS.Internal.Designer.VSIsolatedDesigner.ViewHolder.Initialize()
    à MS.Internal.Designer.VSIsolatedDesigner.ViewHolder..ctor(UIElement content)
    à MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.get_ViewHandle()
    à MS.Internal.Host.Isolation.IsolatedView.get_ViewHandle()
    à MS.Internal.Designer.DesignerPane.LoadDesignerView()
    puis il me propose de recharger le concepteur...sans résultats.

    Merci

  4. #4
    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 : 43
    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
    Bizarre... mais ça c'est juste dans le designer, non ? ça marche en vrai ou pas ?

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 25
    Par défaut
    Non ça ne fonctionne pas, la génération se passe bien mais au moment de l'execution j'ai ce message
    VisualTree de ItemsPanelTemplate doit être un seul élément.

  6. #6
    Membre expérimenté

    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    214
    Détails du profil
    Informations personnelles :
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 214
    Par défaut
    Tu peux nous mettre ton projet de test en pièce jointe pour reproduire facilement le problème sur nos machines ?

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

Discussions similaires

  1. Quote et double quote
    Par aktos dans le forum Langage
    Réponses: 8
    Dernier message: 05/01/2007, 19h55

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