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 Workflow Foundation .NET Discussion :

[UWP] binder Grid.Row et Grid.Column


Sujet :

Windows Workflow Foundation .NET

  1. #1
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut [UWP] binder Grid.Row et Grid.Column
    bonjour,

    j'ai un contentpresenter qui recoit une instance d'objet ayant en propriété un List<machin>
    machin ayant X et Y (int) en propriété (entre autre)

    ce contentpresenter a un datatemplate
    je voudrais un affichage en grille, et que chaque élément se trouve dans la bonne cas via X et Y

    j'étais parti sur un ItemsControl (pour le List<machin>) ayant un ItemsPanel = Grid
    et un ItemTemplate ayant button avec Grid.Row et Grid.Column = {Binding X}

    mais ca ne fonctionne pas, j'ai bien vu quelques workarround sur le net mais qui ne vont pas dans mon cas

    c'est le grid qui est pas codé pour qu'on bind ca ? le button qui trouve pas le grid au dessus ? y a un element au milieu qui fait que grid.row n'est pas atteignable ?
    une autre possibilité que grid pour faire ca ?

    merci
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Si ,si les lignes et colonnes peuvent etre bindés dans un ItemsControl le seul ennui du control Grid c'est qu'il doit :
    - connaitre le nombre de lignes et colonnes en jeu
    - son ItemContainerStyle doit spécifier les bindings "Y"(ligne) et "X"(colonne)...

    De plus , si une ligne ou colonne ne contient aucun élément =>elle semble ne pas s'afficher ,aussi la hauteur et largeur des colonnes doit être impérativement spécifiée..

    En voici un :
    class data de test
    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
    namespace WpfGrid
    {
        public class Item:INotifyPropertyChanged 
        {
            private string nom;
     
            public string Nom
            {
                get { return nom; }
                set
                { 
                    nom = value; Raise("Nom");
                }
            }
            private int col;
     
            public int Col
            {
                get { return col; }
                set 
                {
                    col = value; Raise("Col");
                }
            }
     
            private int row;
     
            public int Row
            {
                get { return row; }
                set
                {
                    row = value; Raise("Row");
                }
            }
     
     
            public event PropertyChangedEventHandler PropertyChanged;
            public void Raise(string nomProp)
            {
                PropertyChangedEventHandler h = PropertyChanged;
                if (h != null)
                    h(this, new PropertyChangedEventArgs(nomProp));
            }
        }
        public class Items: List<Item>
        {
            private Item it;
            public Items()
            {
                    it = new Item() { Nom = "item00", Row=0,Col= 0 };
                    this.Add(it);
                    it = new Item() { Nom = "item21" ,Row= 2, Col = 1 };
                    this.Add(it);
                    it = new Item() { Nom = "item33" ,Row= 3, Col = 3 };
                    this.Add(it);
                    it = new Item() { Nom = "item42" ,Row= 4,Col = 2 };
                    this.Add(it);
                    it = new Item() { Nom = "item52" ,Row= 5 ,Col = 2 };
                    this.Add(it);
                    it = new Item() { Nom = "item53" ,Row= 5, Col = 3 };
                    this.Add(it);
            }
     
     
        }
    code xaml du form:

    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
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    <Window x:Class="WpfGrid.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:local="clr-namespace:WpfGrid" 
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <local:Items x:Key="src"/>
            <DataTemplate 
                x:Key="dt"
                DataType="{x:Type local:Item}">
                <Button
                    Content="{Binding Nom}">
                </Button> 
            </DataTemplate>
        </Window.Resources>
        <StackPanel >
            <ListBox 
                ItemTemplate="{StaticResource dt}"
                ItemsSource="{Binding Source={StaticResource src}}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid IsItemsHost="True"
                              ShowGridLines="True">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition  Width="50"/>
                                <ColumnDefinition  Width="50"/>
                                <ColumnDefinition  Width="50"/>
                                <ColumnDefinition  Width="50"/>
                                <ColumnDefinition  Width="50"/>
                                <ColumnDefinition  Width="50"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition  Height="50"/>
                                <RowDefinition  Height="50"/>
                                <RowDefinition  Height="50"/>
                                <RowDefinition  Height="50"/>
                                <RowDefinition  Height="50"/>
                                <RowDefinition  Height="50"/>
                            </Grid.RowDefinitions>
                        </Grid>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Grid.Column" Value="{Binding Path=Col}" />
                        <Setter Property="Grid.Row" Value="{Binding Path=Row}" />
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
        </StackPanel> 
    </Window>

    une autre possibilité que grid pour faire ca ?
    c'est l' UniformGrid qui permet de spécifier le nombre de colonnes et lignes au lieu d'aligner le code du genre "Grid.ColumnDefinitions ou Grid.RowDefinitions"
    il suffit de "binder ces lignes ou colonnes" à List.Count...
    bon code...

Discussions similaires

  1. Layout grid.row height
    Par hbespoir2003 dans le forum Windows Presentation Foundation
    Réponses: 2
    Dernier message: 02/03/2012, 14h25
  2. Row Editor Grid Example
    Par TsunamiDream dans le forum Ext JS / Sencha
    Réponses: 4
    Dernier message: 20/07/2010, 15h51
  3. Alternative à Grid.Row et Grid.Column ?
    Par zax-tfh dans le forum Silverlight
    Réponses: 5
    Dernier message: 07/05/2010, 02h18
  4. Question bête : 4 zones précises (Grid.row ?)
    Par vincentDec dans le forum Silverlight
    Réponses: 3
    Dernier message: 25/04/2010, 14h05
  5. BackGround + grid.row/column x variable
    Par cKmel dans le forum Windows Presentation Foundation
    Réponses: 10
    Dernier message: 15/11/2009, 18h56

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