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

VB.NET Discussion :

[WPF MVVM] Binding tableau de contrôle utilisateur


Sujet :

VB.NET

  1. #1
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut [WPF MVVM] Binding tableau de contrôle utilisateur
    Bonjour à tous,

    Je n'arrive pas a visualiser comment je peux réduire mon code, je m'explique.

    J'ai une vue qui comporte 120 fois les mêmes objets dans un <TabControl> comportant 4 <TabItem>.
    Chacun de ces 120 objets contiennent des zones simulant des voyants et du texte pour afficher des mesures, en tout 10 informations.
    J'ai donc créer un contrôle utilisateur avec ces 10 zones d'information que je dois implanter sur ma vue.

    Mais cela me fait quand même 120 fois ce contrôle utilisateur.
    voici le 1er Object integrer dans ma vue:

    Code XAML : Sélectionner tout - Visualiser dans une fenêtre à part
    <basic:V_Rectifier Grid.Row="0" Grid.Column="1" DataContext="{Binding Rectifier1}" Margin="2" VerticalAlignment="Top" />

    Ensuite dans ma "Vue Modèle" je sais comment atteindre mes "Property" pour afficher ce que j'ai besoin par le Binding Rectifier1, mais y a t'il un moyen plus facile.

    Même si j'ai les 120 déclarations à faire dans le XAML:

    Code XAML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <basic:V_Rectifier Grid.Row="0" Grid.Column="1" DataContext="{Binding Rectifier1}" Margin="2" VerticalAlignment="Top" />
    <basic:V_Rectifier Grid.Row="0" Grid.Column="2" DataContext="{Binding Rectifier2}" Margin="2" VerticalAlignment="Top" />
    <basic:V_Rectifier Grid.Row="0" Grid.Column="3" DataContext="{Binding Rectifier3}" Margin="2" VerticalAlignment="Top" />
    <basic:V_Rectifier Grid.Row="0" Grid.Column="4" DataContext="{Binding Rectifier3}" Margin="2" VerticalAlignment="Top" />
    <basic:V_Rectifier Grid.Row="0" Grid.Column="5" DataContext="{Binding Rectifier4}" Margin="2" VerticalAlignment="Top" />
    <basic:V_Rectifier Grid.Row="0" Grid.Column="6" DataContext="{Binding Rectifier5}" Margin="2" VerticalAlignment="Top" />
    ...

    Si je pouvais au moins utiliser un tableau dans ma "Vue Modèle" pour faciliter le balayage des données à afficher. Bon Bien sûr je pourrais les réaffecter dans un tableau après avoir effectué la déclaration des 120 property, mais s'il y a un moyen plus simple.

    Bon déjà je viens de constater, en vous écrivant, que je pourrais m’éviter d'utiliser un Grid, mais plutôt un stackpanel horizontal pour chaque ranger de "ControlUser".

    Dans chaque TabItem j'ai 2 rangés de 16 "ControlUser". Le tout dans 4 tabItem.

    Merci

  2. #2
    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
    si tu as une collection de 120 objets ayant x propriétés tu peux faire un itemscontrol avec un itemtemplate, ca génère les 120 uc automatiquement
    un itemscontrol est un listbox sans selection, donc juste pour afficher n choses
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut
    Citation Envoyé par Pol63 Voir le message
    si tu as une collection de 120 objets ayant x propriétés tu peux faire un itemscontrol avec un itemtemplate, ca génère les 120 uc automatiquement
    un itemscontrol est un listbox sans selection, donc juste pour afficher n choses
    J'y est pas du tout pensé, merci, je vais essayer cela.
    Je n'ai que de la visu sur ces objets, sauf le clic. En cliquant sur l'un des "Controluser" j'ouvre une autre vue avec plus de détails ainsi que de la saisie possible.
    Les voyant et mesures sont aussi afficher en temps réel, (enfin suivant le cycle d'une tempo qui interroge et rafraîchi les données).

    Toutefois j'ai vu que l'on doit pouvoir gérer un index de tableau, ICI, mais je n'arrive pas a le mettre en application pour le moment.

    Code XAML : Sélectionner tout - Visualiser dans une fenêtre à part
     <basic:V_Rectifier  DataContext="{Binding Path=[1].Rectifier}" Margin="2" VerticalAlignment="Top" />

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Public Property Rectifier As Dictionary(Of Integer, VM_Rectifier)
    Cela ne fonctionne pas bien sûr, malgré que cela compile sans souci.

  4. #4
    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
    Toutefois j'ai vu que l'on doit pouvoir gérer un index de tableau, ICI, mais je n'arrive pas a le mettre en application pour le moment.
    Ce qui est donné dans ce lien Microsoft concerne le tableau UNIDIMENSIONNEL...
    Mais vu la "quantité" d'infos à visualiser dans une seule fenetre ,ce design me parait peu pertinent pour le "povre" user ...

    Neanmoins tu peux utiliser soit un ItemsControl comme dit par Pol63, soit un List(of List(of T) qui est l'analogue d' un tableau multidimensionel associé ,ou chaque "item principal" correspond à un List(of item) ...
    Pour afficher ce List(of List(of T) , un Listbox exemple(principal) est utilisé dont l'Itemplate contient un autre Listbox bindé à chaque ligne (-List(of item)-)..
    code exemple .vb

    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
    Imports System.ComponentModel
     
    Public Class Item
        Implements INotifyPropertyChanged
        Private m_id As Integer
        Public Property Id() As Integer
            Get
                Return m_id
            End Get
            Set(ByVal value As Integer)
                m_id = value
                OnPropertyChanged("Id")
            End Set
        End Property
     
        Private m_name As String
        Public Property Name As String
            Get
                Return m_name
            End Get
            Set(value As String)
                m_name = value
                OnPropertyChanged("Name")
            End Set
        End Property
        Private m_info As String
        Public Property Info As String
            Get
                Return m_info
            End Get
            Set(value As String)
                m_info = value
                OnPropertyChanged("Info")
            End Set
        End Property
        Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
        Private Sub OnPropertyChanged(propName As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
        End Sub
    End Class
     
     
     
    Imports System.Collections.ObjectModel
    Public Class ListItems
        Inherits ObservableCollection(Of ObservableCollection(Of Item))
     
        Public Sub New()
            Dim arr(119, 9) As Item
     
            For i As Integer = 0 To arr.GetUpperBound(0)
                For j As Integer = 0 To arr.GetUpperBound(1)
                    Dim it As New Item() With {.Id = i, .Name = "Item" + i.ToString + j.ToString, .Info = "Info" + j.ToString}
                    arr(i, j) = it
                Next
            Next
            For i As Integer = 0 To arr.GetUpperBound(0)
                Me.Add(New ObservableCollection(Of Item))
                For j As Integer = 0 To arr.GetUpperBound(1)
                    Me.Item(i).Add(arr(i, j))
                Next
            Next
        End Sub
    End Class
    code xam 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
    <Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:local="clr-namespace:WpfBindArrayMulti" 
        Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <local:ListItems x:Key="items"/>
            <Style x:Key="HorizontalListBox">
                <Setter Property="ListBox.ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <DataTemplate x:Key="CellTemplate"
                          DataType="{x:Type local:Item}">
                <Border BorderThickness="2" BorderBrush="DarkGray" 
                   CornerRadius="2"  >
                    <StackPanel Orientation="Horizontal">
                        <Button Margin="5"  Content="ShowViewA"/>
                        <TextBlock Margin="5" Text="{Binding Id}"/>
                        <TextBlock Margin="5" Text="{Binding Name}"/>
                        <TextBlock Margin="5" Text="{Binding Info}"/>
                    </StackPanel>
     
                </Border>
            </DataTemplate>
            <DataTemplate x:Key="RowTemplate"
                          >
                <ListBox  
                    BorderThickness="0"
                       ItemsSource="{Binding}" 
                       Style="{StaticResource HorizontalListBox}" 
                       ItemTemplate="{StaticResource CellTemplate}" />
            </DataTemplate>
        </Window.Resources>
        <Grid>
            <ListBox 
                x:Name="lb"
                ItemsSource="{Binding  Source={StaticResource items}}" 
                ItemTemplate="{StaticResource RowTemplate}" />
        </Grid>
    </Window>
    pas de code behind...

    nb: vu cette interface un peu "rebutante" ,il vaut mieux utiliser trois UserControl en dispatchant le tableau via 4 tabitems...(pagination)....

  5. #5
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut
    Merci à vous pour toutes ces précisions,

    Hier soir j'ai regardé du coté de ce que m'a proposé Pol63, mais j'avoue que les exemple trouvé sur le net ne mon pas beaucoup aidé. Je vais donc regarder ce matin ton exemple MABROUKI et continuer à chercher, en espérant que j'arrive à le comprendre.

    Voici ma présentation actuel:

    Nom : RectifierPlant.png
Affichages : 415
Taille : 41,7 Ko

    Sur cette photo les couleurs sont posés sur le Control user à des fin de test, et le dernier objet avec un "1" devra être renseigner avec le numéro du redresseur concerné (rectifier) de 1 à 120 donc.

    Le système en face est modulaire, donc il n'y aura pas tous le temps 120 redresseurs, c'est le max admissible. Je dois mettre à jour uniquement les redresseurs présent. J'ai une procédure pour récupérer le nombre et la position des redresseurs.

    Mon logiciel est nouveau (1er logiciel réaliser en WPF et en autoformation, un grand merci à la communauté "Developpez.net" en passant), mais l'architecture est issue d'une base réalisée en VB6, j'en garde un maximum d’algorithme et de logique, afin de ne pas trop s'y perdre lors de la maintenance ou modification, mais WPF change radicalement la manière d’accéder à la vue bien sûr, surtout en essayant de respecter le patern MVVM.
    En Vb6 tous les objets sont sur la vue (120x10 sans compter les autres object sur une autre page du tabcontrol), pas de usercontrol, mais par exemple, les voyants Installed (ici en rouge) sont des tableaux d'image déclarer directement dans la vue par les index, ce qui n'existe plus depuis Dotnet.
    Ensuite pour le traitement ce ne sont que des boucles de chaque ligne qui sont mise à jour.


    Le code originel en VB6 n'est pas de moi.

    Merci encore.

    [EDIT]
    Je viens de monter un projet test avec votre code MABROUKI, bien-sûr tel quel ce n'est pas l'idéal, question ergonomie pour l'utilisateur, il faut que je le repartisse sur plusieurs page, ou utiliser uniquement la scrollbar horizontal, mais votre exemple est clair et me permet de comprendre un peu mieux le principe, merci beaucoup.

    En reprenant la vue exemple (photo) ci dessous que je vous est mis ce matin, chaque onglet (header) du tabcontrol contient aussi un voyant à coté du texte. Ce voyant doit s'allumer si dans les éléments présent une alarme est activé sur au moins l'un des redresseurs surveillé, afin d’alerter l'utilisateur et qu'il y accède rapidement. Avec un gros scrolling, c'est moins facile pour l'utilisateur, mais je vais creuser la question.

    Merci.

  6. #6
    Expert confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2009
    Messages
    2 025
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2009
    Messages : 2 025
    Points : 5 462
    Points
    5 462
    Par défaut
    Utilises une ObservableCollection à la place d'un dictionnaire pour Rectifier.

    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
    <Grid>
      ............
       ....... Affichage de "Installed" "Logged"......
       .........
    <ItemsControl ItemsSource="{Binding Path=Rectifier, Mode=OneWay}" Grid.Column=1 >
        <ItemsControl.ItemTemplate>
            <DataTemplate >
                 <basic:V_Rectifier Margin="2" VerticalAlignment="Top" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate >
                <StackPanel Orientation="Vertical" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
     
    </Grid>

  7. #7
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut
    Bonjour,

    J'ai pas mal avancé. En partant du code de MABROUKI, je l'ai adapté à ma situation et cela fonctionne pas mal du tout. J'ai juste une petite question que je vous pose a la fin.

    J'ai monté un projet WPF seul pour tester, ensuite j'aimerais donc l’intégrer dans mon projet en passant pas un ControlUser.

    Voici ma Classe "Rectifier" monté à partir de la classe "Item" de MABROUKI.

    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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    Imports System.ComponentModel
    Public Class Rectifier
        Implements INotifyPropertyChanged
     
        Private m_Installed_Color As SolidColorBrush = Brushes.Gray
        Public Property Installed_Color As SolidColorBrush
            Get
                Return m_Installed_Color
            End Get
            Set(value As SolidColorBrush)
                m_Installed_Color = value
                OnPropertyChanged("Installed_Color")
            End Set
        End Property
        Private m_Installed_Text As String = ""
        Public Property Installed_Text As String
            Get
                Return m_Installed_Text
            End Get
            Set(value As String)
                m_Installed_Text = value
                OnPropertyChanged("Installed_Text")
            End Set
        End Property
     
        Private m_Logged_Color As SolidColorBrush = Brushes.Gray
        Public Property Logged_Color As SolidColorBrush
            Get
                Return m_Logged_Color
            End Get
            Set(value As SolidColorBrush)
                m_Logged_Color = value
                OnPropertyChanged("Logged_Color")
            End Set
        End Property
     
        Private m_Logged_Text As String = ""
        Public Property Logged_Text As String
            Get
                Return m_Logged_Text
            End Get
            Set(value As String)
                m_Logged_Text = value
                OnPropertyChanged("Logged_Text")
            End Set
        End Property
     
        Private m_Idle_Color As SolidColorBrush = Brushes.Gray
        Public Property Idle_Color As SolidColorBrush
            Get
                Return m_Idle_Color
            End Get
            Set(value As SolidColorBrush)
                m_Idle_Color = value
                OnPropertyChanged("Idle_Color")
            End Set
        End Property
        Private m_Idle_Text As String = ""
        Public Property Idle_Text As String
            Get
                Return m_Idle_Text
            End Get
            Set(value As String)
                m_Idle_Text = value
                OnPropertyChanged("Idle_Text")
            End Set
        End Property
     
        Private m_NotDetected_Color As SolidColorBrush = Brushes.Gray
        Public Property NotDetected_Color As SolidColorBrush
            Get
                Return m_NotDetected_Color
            End Get
            Set(value As SolidColorBrush)
                m_NotDetected_Color = value
                OnPropertyChanged("NotDetected_Color")
            End Set
        End Property
        Private m_NotDetected_Text As String = ""
        Public Property NotDetected_Text As String
            Get
                Return m_NotDetected_Text
            End Get
            Set(value As String)
                m_NotDetected_Text = value
                OnPropertyChanged("NotDetected_Text")
            End Set
        End Property
     
        Private m_MajorAlarm_Color As SolidColorBrush = Brushes.Gray
        Public Property MajorAlarm_Color As SolidColorBrush
            Get
                Return m_MajorAlarm_Color
            End Get
            Set(value As SolidColorBrush)
                m_MajorAlarm_Color = value
                OnPropertyChanged("MajorAlarm_Color")
            End Set
        End Property
        Private m_MajorAlarm_Text As String = ""
        Public Property MajorAlarm_Text As String
            Get
                Return m_MajorAlarm_Text
            End Get
            Set(value As String)
                m_MajorAlarm_Text = value
                OnPropertyChanged("MajorAlarm_Text")
            End Set
        End Property
     
        Private m_MinorAlarm_Color As SolidColorBrush = Brushes.Gray
        Public Property MinorAlarm_Color As SolidColorBrush
            Get
                Return m_MinorAlarm_Color
            End Get
            Set(value As SolidColorBrush)
                m_MinorAlarm_Color = value
                OnPropertyChanged("MinorAlarm_Color")
            End Set
        End Property
        Private m_MinorAlarm_Text As String = ""
        Public Property MinorAlarm_Text As String
            Get
                Return m_MinorAlarm_Text
            End Get
            Set(value As String)
                m_MinorAlarm_Text = value
                OnPropertyChanged("MinorAlarm_Text")
            End Set
        End Property
     
     
        Private m_Current As String = "- - -"
        Public Property Current As String
            Get
                Return m_Current
            End Get
            Set(value As String)
                m_Current = value
                OnPropertyChanged("Current")
            End Set
        End Property
        Private m_Temperature As String = "- - -"
        Public Property Temperature As String
            Get
                Return m_Temperature
            End Get
            Set(value As String)
                m_Temperature = value
                OnPropertyChanged("Temperature")
            End Set
        End Property
        Private m_Tension As String = "- - -"
        Public Property Tension As String
            Get
                Return m_Tension
            End Get
            Set(value As String)
                m_Tension = value
                OnPropertyChanged("Tension")
            End Set
        End Property
     
        Private m_idx As String
        Public Property Idx As String
            Get
                Return m_idx
            End Get
            Set(ByVal value As String)
                m_idx = value
                OnPropertyChanged("Idx")
            End Set
        End Property
     
     
        Private m_TXT_Current_Foreground As SolidColorBrush = Brushes.Yellow
        Public Property TXT_Current_Foreground As SolidColorBrush
            Get
                Return m_TXT_Current_Foreground
            End Get
            Set(value As SolidColorBrush)
                m_TXT_Current_Foreground = value
                OnPropertyChanged("TXT_Current_Foreground")
            End Set
        End Property
        Private m_TXT_Current_Fontsize As Integer = 9
        Public Property TXT_Current_Fontsize As Integer
            Get
                Return m_TXT_Current_Fontsize
            End Get
            Set(value As Integer)
                m_TXT_Current_Fontsize = value
                OnPropertyChanged("TXT_Current_Fontsize")
            End Set
        End Property
        Private m_TXT_Temperature_Foreground As SolidColorBrush = Brushes.Yellow
        Public Property TXT_Temperature_Foreground As SolidColorBrush
            Get
                Return m_TXT_Temperature_Foreground
            End Get
            Set(value As SolidColorBrush)
                m_TXT_Temperature_Foreground = value
                OnPropertyChanged("TXT_Temperature_Foreground")
            End Set
        End Property
        Private m_TXT_Temperature_Fontsize As Integer = 9
        Public Property TXT_Temperature_Fontsize As Integer
            Get
                Return m_TXT_Temperature_Fontsize
            End Get
            Set(value As Integer)
                m_TXT_Temperature_Fontsize = value
                OnPropertyChanged("TXT_Temperature_Fontsize")
            End Set
        End Property
        Private m_TXT_Tension_Foreground As SolidColorBrush = Brushes.Yellow
        Public Property TXT_Tension_Foreground As SolidColorBrush
            Get
                Return m_TXT_Tension_Foreground
            End Get
            Set(value As SolidColorBrush)
                m_TXT_Tension_Foreground = value
                OnPropertyChanged("TXT_Tension_Foreground")
            End Set
        End Property
        Private m_TXT_Tension_Fontsize As Integer = 9
        Public Property TXT_Tension_Fontsize As Integer
            Get
                Return m_TXT_Tension_Fontsize
            End Get
            Set(value As Integer)
                m_TXT_Tension_Fontsize = value
                OnPropertyChanged("TXT_Tension_Fontsize")
            End Set
        End Property
        Private m_TXT_Id_Foreground As SolidColorBrush
        Public Property TXT_Id_Foreground As SolidColorBrush
            Get
                Return m_TXT_Id_Foreground
            End Get
            Set(value As SolidColorBrush)
                m_TXT_Id_Foreground = value
                OnPropertyChanged("TXT_Id_Foreground")
            End Set
        End Property
        Private m_TXT_Id_Fontsize As Integer = 11
        Public Property TXT_Id_Fontsize As Integer
            Get
                Return m_TXT_Id_Fontsize
            End Get
            Set(value As Integer)
                m_TXT_Id_Fontsize = value
                OnPropertyChanged("TXT_Id_Fontsize")
            End Set
        End Property
     
     
        Private m_CMD_General_Background As SolidColorBrush = Brushes.Bisque
        Public Property CMD_General_Background As SolidColorBrush
            Get
                Return m_CMD_General_Background
            End Get
            Set(value As SolidColorBrush)
                m_CMD_General_Background = value
                OnPropertyChanged("CMD_General_Background")
            End Set
        End Property
        Private m_CMD_General_BorderBrush As SolidColorBrush = Brushes.Black
        Public Property CMD_General_BorderBrush As SolidColorBrush
            Get
                Return m_CMD_General_BorderBrush
            End Get
            Set(value As SolidColorBrush)
                m_CMD_General_BorderBrush = value
                OnPropertyChanged("CMD_General_BorderBrush")
            End Set
        End Property
        Private m_CMD_General_BorderThickness As Integer = 1
        Public Property CMD_General_BorderThickness As Integer
            Get
                Return m_CMD_General_BorderThickness
            End Get
            Set(value As Integer)
                m_CMD_General_BorderThickness = value
                OnPropertyChanged("CMD_General_BorderThickness")
            End Set
        End Property
        Private m_BORDER_General_BorderThickness As Integer = 2
        Public Property BORDER_General_BorderThickness As Integer
            Get
                Return m_BORDER_General_BorderThickness
            End Get
            Set(value As Integer)
                m_BORDER_General_BorderThickness = value
                OnPropertyChanged("BORDER_General_BorderThickness")
            End Set
        End Property
        Private m_BORDER_General_BorderBrush As SolidColorBrush = Brushes.Black
        Public Property BORDER_General_BorderBrush As SolidColorBrush
            Get
                Return m_BORDER_General_BorderBrush
            End Get
            Set(value As SolidColorBrush)
                m_BORDER_General_BorderBrush = value
                OnPropertyChanged("BORDER_General_BorderBrush")
            End Set
        End Property
        Private m_BORDER_General_Width As Integer = 31
        Public Property BORDER_General_Width As Integer
            Get
                Return m_BORDER_General_Width
            End Get
            Set(value As Integer)
                m_BORDER_General_Width = value
                OnPropertyChanged("BORDER_General_Width")
            End Set
        End Property
        Private m_BORDER_General_Height As Integer = 18
        Public Property BORDER_General_Height As Integer
            Get
                Return m_BORDER_General_Height
            End Get
            Set(value As Integer)
                m_BORDER_General_Height = value
                OnPropertyChanged("BORDER_General_Height")
            End Set
        End Property
        Private m_BORDER_General_Background As SolidColorBrush = Brushes.Gray
        Public Property BORDER_General_Background As SolidColorBrush
            Get
                Return m_BORDER_General_Background
            End Get
            Set(value As SolidColorBrush)
                m_BORDER_General_Background = value
                OnPropertyChanged("BORDER_General_Background")
            End Set
        End Property
     
        Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
        Private Sub OnPropertyChanged(propName As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
        End Sub
    End Class
    Ensuite la Classe ListRectifiers avec comme base la classe "ListItems"


    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
    Imports System.Collections.ObjectModel
    Public Class ListRectifiers
        'Inherits ObservableCollection(Of Item)
        Inherits ObservableCollection(Of ObservableCollection(Of Rectifier))
        Public Sub New()
            Dim arr(7, 15) As Rectifier
            Dim idx As Integer = 0
            For i As Integer = 0 To arr.GetUpperBound(0)
                For j As Integer = 0 To arr.GetUpperBound(1)
     
                    Dim it As New Rectifier()
                    If j = 0 Then
                        it.Installed_Color = Brushes.Transparent
                        it.Installed_Text = "Installed"
                        it.Logged_Color = Brushes.Transparent
                        it.Logged_Text = "Logged"
                        it.Idle_Color = Brushes.Transparent
                        it.Idle_Text = "Idle"
                        it.NotDetected_Color = Brushes.Transparent
                        it.NotDetected_Text = "Not Detected"
                        it.MajorAlarm_Color = Brushes.Transparent
                        it.MajorAlarm_Text = "Major Alarm"
                        it.MinorAlarm_Color = Brushes.Transparent
                        it.MinorAlarm_Text = "Minor Alarm"
                        it.TXT_Current_Foreground = Brushes.Black
                        it.Current = "Current"
                        it.TXT_Temperature_Foreground = Brushes.Black
                        it.Temperature = "Temperature"
                        it.TXT_Tension_Foreground = Brushes.Black
                        it.Tension = "VAC"
                        it.Idx = ""
                        it.BORDER_General_BorderBrush = Brushes.Transparent
                        it.BORDER_General_Width = 80
                        it.CMD_General_BorderBrush = Brushes.Transparent
                        it.BORDER_General_Background = Brushes.Transparent
                        it.Idx = ""
                    Else
                        idx += 1
                        it.Idx = idx.ToString
                    End If
                    arr(i, j) = it
                Next
            Next
     
            For i As Integer = 0 To arr.GetUpperBound(0)
                Me.Add(New ObservableCollection(Of Rectifier))
                For j As Integer = 0 To arr.GetUpperBound(1)
                    Me.Item(i).Add(arr(i, j))
                Next
            Next
     
        End Sub
     
    End Class

    Ensuite la vue XAML:

    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
    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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    <Window x:Class="MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp8"
            mc:Ignorable="d"
            Title="MainWindow" Height="425" Width="815"
            Background="{Binding FORM_General_Background, FallbackValue='Bisque'}">
        <Window.Resources>
            <local:ListRectifiers x:Key="items"/>
            <Style x:Key="HorizontalListBox">
                <Setter Property="ListBox.ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <DataTemplate x:Key="CellTemplate"
                          DataType="{x:Type local:Rectifier}">
                <Button Background="{Binding CMD_General_Background,FallbackValue='Bisque'}" 
                        BorderBrush="{Binding CMD_General_BorderBrush,FallbackValue='Black'}" 
                        Cursor="Hand" 
                        BorderThickness="{Binding CMD_General_BorderThickness,FallbackValue='1'}"
                        Command="{Binding CMD_Rectifier}">
     
                    <StackPanel Orientation="Vertical">
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                CornerRadius="1" 
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}"
                                Background="{Binding Installed_Color,FallbackValue='Gray'}" >
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Title_Foreground,FallbackValue='Black'}"
                                       FontSize="{Binding TXT_Title_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding Installed_Text, FallbackValue=''}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                CornerRadius="1" 
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}"
                                Background="{Binding Logged_Color,FallbackValue='LightGreen'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Title_Foreground,FallbackValue='Black'}"
                                       FontSize="{Binding TXT_Title_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding Logged_Text, FallbackValue=''}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                CornerRadius="1" 
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}"
                                Background="{Binding Idle_Color,FallbackValue='LightGreen'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Title_Foreground,FallbackValue='Black'}"
                                       FontSize="{Binding TXT_Title_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding Idle_Text, FallbackValue=''}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                CornerRadius="1" 
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}"
                                Background="{Binding NotDetected_Color,FallbackValue='LightGreen'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Title_Foreground,FallbackValue='Black'}"
                                       FontSize="{Binding TXT_Title_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding NotDetected_Text, FallbackValue=''}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                CornerRadius="1" 
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}"
                                Background="{Binding MajorAlarm_Color,FallbackValue='LightGreen'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Title_Foreground,FallbackValue='Black'}"
                                       FontSize="{Binding TXT_Title_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding MajorAlarm_Text, FallbackValue=''}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                CornerRadius="1" 
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}"
                                Background="{Binding MinorAlarm_Color,FallbackValue='LightGreen'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Title_Foreground,FallbackValue='Black'}"
                                       FontSize="{Binding TXT_Title_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding MinorAlarm_Text, FallbackValue=''}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                Background="{Binding BORDER_General_Background,FallbackValue='Gray'}" 
                                CornerRadius="1"
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Current_Foreground,FallbackValue='Yellow'}"
                                       FontSize="{Binding TXT_Current_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding Current, FallbackValue='30,2'}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                Background="{Binding BORDER_General_Background,FallbackValue='Gray'}" 
                                CornerRadius="1"
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Temperature_Foreground,FallbackValue='Yellow'}"
                                       FontSize="{Binding TXT_Temperature_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding Temperature, FallbackValue='- - -'}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                Background="{Binding BORDER_General_Background,FallbackValue='Gray'}" 
                                CornerRadius="1"
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Tension_Foreground,FallbackValue='Yellow'}"
                                       FontSize="{Binding TXT_Tension_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding Tension, FallbackValue='- - -'}"/>
                        </Border>
                        <Border BorderBrush="{Binding BORDER_General_BorderBrush, FallbackValue='Black'}"  
                                BorderThickness="{Binding BORDER_General_BorderThickness, FallbackValue='2'}" 
                                Background="{Binding BORDER_General_Background,FallbackValue='Gray'}" 
                                CornerRadius="1"
                                Height="{Binding BORDER_General_Height,FallbackValue='15'}" 
                                Width="{Binding BORDER_General_Width,FallbackValue='25'}">
                            <TextBlock Background="Transparent" 
                                       Foreground= "{Binding TXT_Tension_Foreground,FallbackValue='Yellow'}"
                                       FontSize="{Binding TXT_Tension_Fontsize,FallbackValue='9'}"
                                       Margin="0,1,0,1" TextAlignment="Center" VerticalAlignment ="Center"
                                       Text="{Binding Idx, FallbackValue='- - -'}"/>
                        </Border>
     
     
                    </StackPanel>
                </Button> 
     
            </DataTemplate>
            <DataTemplate x:Key="RowTemplate"
                          >
                <ListBox  
                    BorderThickness="0"
                        Background="Bisque" 
                       ItemsSource="{Binding}" 
                       Style="{StaticResource HorizontalListBox}" 
                       ItemTemplate="{StaticResource CellTemplate}" />
            </DataTemplate>
        </Window.Resources>
        <Grid>
            <ListBox 
                x:Name="lb"
                ItemsSource="{Binding  Source={StaticResource items}}" 
                ItemTemplate="{StaticResource RowTemplate}" 
                Background="Bisque"/>
        </Grid>
    </Window>


    Je suis donc partie avec une seul grosse listbox d'une largeur permettant d'afficher 15 redresseurs + la 1ere colonne (0) affichant le Texte de désignation.
    Le scrollbar verticale me permet de visualiser la totalité des 120 redresseurs.

    Dans ma classe Rectifier, j'ai pas mal de propriétés, pour m'adapter à plusieurs situations, comme pour la 1ere colonne par exemple qui n'affiche que du Texte.
    Les voyants sont simplement réalisé pour le moment par le changement de la couleur du background du Border.

    Il y a peut-être un moyen plus simple de gérer cette 1ere colone, mais cela fonctionne.

    Voici une vue du résultat:

    Nom : RectifierPlant2.png
Affichages : 387
Taille : 52,6 Ko

    Je n'utilise donc pas le ControlUser que j'avais créer avant qui ne contenant que les 10 champs, mais j'ai repris la même base pour l’intégrer au DataTemplate.


    Ma Question qui peut tout conditionner par la suite:

    Mon but est d'afficher des données en temps réel, il faut donc que j’accède à la classe ListRrectifiers (Observablecollection).
    Par quel moyen je vais y accéder depuis le VueModel, qui va contenir ce gros ControlUser?

    Je vais commencé à l’intégrer et voir comment cela ce comporte.

    Autre petite question moins gênante, mais y a t'il un moyen de réduire l'espace entre chaque colonne?

    En tout cas merci à vous tous.

    [Edit] J'ai pas encore traité la partie commande du bouton.

    [Edit2] La partie commande est désormais gérée, cela fonctionne. J'ai installé le tout dans mon soft, la vue des 120 redresseurs est désormais un Control-user, par contre les Templates, je ne pouvait pas les laisser dans le XAML de ce Control-user, je lai transféré dans l'Application.xaml, je sais pas si c'est une bonne pratique, surtout que ce sera utilisé que pour cette partie.

  8. #8
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut
    Bonjour à tous,

    J'ai trouvé le moyen d’accéder à ma collection.
    Je sort un peu de la logique du logiciel, mais j’ai mi en place les routines d’interrogation de l'automate (pour avoir les mesures et alarmes), directement dans la classe rectifier, j'ai donc toutes me variables présente, reste à voir si tout se met bien à jour.


    J’aurai une autre question qui sort un peu du contexte: Est-ce qu'il est possible de savoir quelle ligne de la listbox, sont bien visibles. Afin d'éviter d’interroger les 120 redresseur en permanence.

    L'utilisateur peux voir 30 redresseurs max, pour voir les autres il faut descendre le scrollbar, j'aimerai donc interrogé uniquement ceux qui sont visible et donc avoir soit la position du scrollbar ou encore mieux, les lignes visible. Est-ce possible?

  9. #9
    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
    y a des chances mais ca me parait inutile
    interroger 120 trucs ca ne consomme rien par rapport au reste
    quand le gars va scroller s'il doit attendre avoir d'avoir l'affichage il verra des choses potentiellement fausses pendant un lapse de temps
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  10. #10
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut
    Citation Envoyé par Pol63 Voir le message
    y a des chances mais ca me parait inutile
    interroger 120 trucs ca ne consomme rien par rapport au reste
    quand le gars va scroller s'il doit attendre avoir d'avoir l'affichage il verra des choses potentiellement fausses pendant un lapse de temps

    Coté PC cela ne dérange pas c'est certains, et je l'accorde en local sur le port COM cela ne devrait pas non plus pauser trop de souci. Mais parfois certain site n'ont pas de moyen de communication à part le satellite et la c'est une autre histoire... passer par un modem satellite c'est l'horreur.
    On a eue le cas même en France, en montage, ou aucun autre moyen de com. était disponible, il a fallu que l'on adapte notre logiciel pour éviter d'avoir des questions réponses incessantes, mais plutôt une question puis une réponse nous envoyant la totalité des info.
    Par exemple à la connexion on récupère la configuration complète du site, cela contient toutes les données. Interroger chaque élément et attendre la réponse faisait planté la liaison satellite.

    On utilise aussi la liaison ethernet, mais c'est une passerelle entre le Port COM et le réseau.


    Sinon je regarde le principe de la pagination, MABROUKI en parlait aussi dans son exemple. J'ai posté une autre question dans ce sens pour ne pas trop polluer cette discussion, même si c'est en lien.

  11. #11
    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

    Voici une autre facon de gérer ton problème UI qui montre que celui-ci se reduit en fait à un "problème" d'un class de type hiérarchique...

    code .vb du class data
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Public Class Item
     
        Public Property Id() As Integer
        Public Property Name As String
        Public Property SelectedItem As Item
        Public Property Items As List(Of Item)
        Public Sub New()
            Items = New List(Of Item)
        End Sub
    End Class
    code .vb du class ViewModel:
    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
    Imports System.ComponentModel
    Public Class BaseModel
        Implements INotifyPropertyChanged
     
        Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
        Public Sub OnPropertyChanged(propName As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
        End Sub
    End Class
     
    Public Class ItemModel
        Inherits BaseModel
        Private it As New Item
        Public Sub New()
     
        End Sub
        Public Property Id() As Integer
            Get
                Return it.Id
            End Get
            Set(value As Integer)
                it.Id = value
                OnPropertyChanged("Id")
            End Set
        End Property
        Public Property Name As String
            Get
                Return it.Name
            End Get
            Set(value As String)
                it.Name = value
                OnPropertyChanged("Name")
            End Set
        End Property
        Public Property SelectedItem As Item
            Get
                Return it.SelectedItem
            End Get
            Set(value As Item)
                it.SelectedItem = value
                OnPropertyChanged("SelectedItem")
            End Set
        End Property
        Public Property Items As List(Of Item)
            Get
                Return it.Items
            End Get
            Set(value As List(Of Item))
                it.Items = value
                OnPropertyChanged("Items")
            End Set
        End Property
     
    End Class
     
    Public Class MainModel
        Inherits BaseModel
     
        Public Sub New()
            LoadItems()
        End Sub
        Public Property SelectedItem() As Item
            Get
                Return SelectedItemModel.SelectedItem
            End Get
            Set(ByVal value As Item)
                SelectedItemModel.SelectedItem = value
                OnPropertyChanged("SelectedItem")
            End Set
        End Property
        Private m_selectedItemModel As ItemModel
        Public Property SelectedItemModel() As ItemModel
            Get
                Return m_selectedItemModel
            End Get
            Set(ByVal value As ItemModel)
                m_selectedItemModel = value
                OnPropertyChanged("SelectedItemModel")
            End Set
        End Property
        Private m_itemsModel As List(Of ItemModel)
        Public Property ItemsModel() As List(Of ItemModel)
            Get
                Return m_itemsModel
            End Get
            Set(ByVal value As List(Of ItemModel))
                m_itemsModel = value
                OnPropertyChanged("ItemsModel")
            End Set
        End Property
     
        Private Sub LoadItems()
            m_itemsModel = New List(Of ItemModel)
            For i As Integer = 0 To 3
                Dim itModel As New ItemModel With {.Id = i, .Name = "item" + i.ToString, .Items = New List(Of Item)}
                For j As Integer = 0 To 5
                    itModel.Items.Add(New Item() With {.Id = j, .Name = "item" + j.ToString})
                Next
                m_itemsModel.Add(itModel)
            Next
     
     
        End Sub
    End Class
    code xaml du Form (ou usercontrol) qui permet de modifier un ItemModel,voire l'ajouter ou le supprimer grace au pattern command:

    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
    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
    <Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfMovies" 
        Title="MainWindow" Height="350" Width="525">
        <Window.DataContext>
            <local:MainModel></local:MainModel>
        </Window.DataContext>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Border 
                Grid.Column="0"
                Margin="5"
                BorderBrush="Red" 
                BorderThickness="2"
                CornerRadius="8">
                <ListView 
                    x:Name="lv"
                    SelectedIndex="0"
                    SelectedItem="{Binding SelectedItemModel,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                    ItemsSource="{Binding ItemsModel}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ListView 
                                SelectedItem="{Binding SelectedItem,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                ItemsSource="{Binding Items}">
                                <ListView.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel  Orientation="Horizontal"/> 
                                    </ItemsPanelTemplate>
                                </ListView.ItemsPanel>
                                <ListView.ItemTemplate>
                                    <DataTemplate DataType="{x:Type local:Item}">
                                        <StackPanel 
                                            Orientation="Horizontal">
                                            <TextBlock Margin="5" Text="{Binding Id}" />
                                            <TextBlock Margin="5" Text="{Binding Name}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                    <!--on ajoute un padding suffisant pour pouvoir selection:
                    soit l'itemModel ,soit ses enfants-->
                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="Padding" Value="10"/>
     
                        </Style>
                    </ListView.ItemContainerStyle>
                </ListView>
            </Border>
            <StackPanel Grid.Column="1">
                <Border 
                    Margin="5"
                    BorderBrush="Blue" 
                    BorderThickness="2"
                    CornerRadius="8">
                    <StackPanel>
                        <Label FontSize="14"  FontStyle="Italic" Content="ItemModel Row"/>
                        <TextBlock Text="{Binding Path=SelectedItemModel.Id}"/>
                        <TextBlock Text="{Binding Path=SelectedItemModel.Name}"/>
                    </StackPanel>
                </Border>
                <Border 
                    Margin="5"
                    BorderBrush="Blue" 
                    BorderThickness="2"
                    CornerRadius="8">
                <StackPanel>
                        <Label FontSize="14" FontStyle="Italic" Content="ItemModel Detail Row"/>
                        <TextBlock Text="{Binding Path=SelectedItemModel.SelectedItem.Id}"/>
                        <TextBlock Text="{Binding Path=SelectedItemModel.SelectedItem.Name}"/>
                </StackPanel>
            </Border>
            </StackPanel>
        </Grid>
    </Window>
    bon code...

  12. #12
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut
    Bonjour à tous,

    Je suis un peu, beaucoup dans la panade.

    Je m'explique:
    Mon code semble fonctionner, je dit semble, car j'ai n'est pas le système complet de raccordé avec les redresseurs, donc quand j’interroge l'automate, j'ai pas de réponse correct, mais que des erreurs, que j'intercepte et je les remplace par ce que je devrais avoir quand tout sera en place.

    Seulement je suis resté sur mon code que je vous est présenté plus haut. Je fait donc 120 requêtes.

    Pour le moment j'ai pas trouvé de tuto qui m'a permis d’intégrer le paging, et je ne comprend pas bien les derniers code de MABROUKI.

    De tuto j'en ai trouvé pour des Datagrid. Notamment ICI, je l'ai converti en VB puis essayé d’adapter à mon utilisation, mais je n'arrive pas à intégrer dans chaque colonne un Usercontrol.


    Si vous avez quelques minute à perdre, je vais voir aussi avec mon fils qui est développeur aussi, mais il a été plus loin que moi il viens de sortir de polytech et connais un peu notre boulot pour y avoir effectuer un stage, au cas ou il a une autre idée.

  13. #13
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut
    Bonjour à tous,

    La nuit m'a portée conseil encore une fois, encore qu'a la place j'aurai aimer dormir .

    J'ai trouvé une solution, en gardant mon code.
    J'ai non pas créer 1 mais 4 listbox. Chacune appelant 4 ListRectifiers.

    Code XAML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     <UserControl.Resources>
            <local:ListRectifiers1 x:Key="itemsRect1"/>
            <local:ListRectifiers2 x:Key="itemsRect2"/>
            <local:ListRectifiers3 x:Key="itemsRect3"/>
            <local:ListRectifiers4 x:Key="itemsRect4"/>


    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
    <ListBox x:Name="listbox1"
                     ItemsSource="{Binding  Source={StaticResource itemsRect1}}" 
                     ItemTemplate="{StaticResource RowTemplate}" 
                     Background="Bisque"/>
            <ListBox x:Name="listbox2"
                     ItemsSource="{Binding  Source={StaticResource itemsRect2}}" 
                     ItemTemplate="{StaticResource RowTemplate}" 
                     Background="Bisque"/>
            <ListBox x:Name="listbox3"
                     ItemsSource="{Binding  Source={StaticResource itemsRect3}}" 
                     ItemTemplate="{StaticResource RowTemplate}" 
                     Background="Bisque"/>
            <ListBox x:Name="listbox4"
                     ItemsSource="{Binding  Source={StaticResource itemsRect4}}" 
                     ItemTemplate="{StaticResource RowTemplate}" 
                     Background="Bisque"/>

    Elle sont les une sur les autres et je les masque ou pas suivant une variable globale qui m'indique la page à afficher
    J'ai ajouté un timer dans la View.xaml.vb (du ControlUser). il ne fait que vérifier la page à afficher et ensuite rend visible ou pas.

    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
        Private pageSave As Integer
        Private Sub Timer_Tick()
            If pageSave <> PageEncours Then
                pageSave = PageEncours
                Select Case PageEncours
                    Case 1
                        listbox1.Visibility = Visibility.Visible
                        listbox2.Visibility = Visibility.Collapsed
                        listbox3.Visibility = Visibility.Collapsed
                        listbox4.Visibility = Visibility.Collapsed
                    Case 2
                        listbox1.Visibility = Visibility.Collapsed
                        listbox2.Visibility = Visibility.Visible
                        listbox3.Visibility = Visibility.Collapsed
                        listbox4.Visibility = Visibility.Collapsed
                    Case 3
                        listbox1.Visibility = Visibility.Collapsed
                        listbox2.Visibility = Visibility.Collapsed
                        listbox3.Visibility = Visibility.Visible
                        listbox4.Visibility = Visibility.Collapsed
                    Case 4
                        listbox1.Visibility = Visibility.Collapsed
                        listbox2.Visibility = Visibility.Collapsed
                        listbox3.Visibility = Visibility.Collapsed
                        listbox4.Visibility = Visibility.Visible
                End Select
            End If
     
        End Sub
    Je me sert aussi de cette variable PageEnCours dans la Class "Rectifier", là ou j'ai toutes mes variables du Datatemplate, avec aussi un timer afin d'activer uniquement le rafraîchissement des données visibles.

    Merci de votre aide en tout cas.

  14. #14
    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

    Voici en bonus le code de paging qui est au fond un concept simple .
    car on doit gérer 3 variables maxi:
    - numero de page courante
    - taille de page
    - liste d'elements à paginer
    Plus -quatre buttons de navigation (firstpage,prevpage,nextpage, lastpage) associes...

    voici le même code de base que lcelui du premier Post déjà communique ci-e premier qui intègre en plus un Paging ou Pagination (ListItens se trouve maintenant dans le Class MainModel ,en plus d'une Collection Page )...
    Le code xaml affiche pour illustration la Liste Source complète à des fins d'illustration pou inspecter celle-ci et constater qu'elle reflète les modifs de la liste Page...
    4 Buttons avec binding sur un relaycommd rythme la musique
    Trois TextBox permmettent de modifier les fields de l'element Item sélectionné dans la Page...

    Code .vb revu :
    1/class data
    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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    Imports System.ComponentModel
    Public Class BaseItem
        Implements INotifyPropertyChanged
     
        Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
        Public Sub NotifyPropertyChanged(propName As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
        End Sub
    End Class
    Public Class Item
        Inherits BaseItem
        Private m_id As Integer
        Public Property Id() As Integer
            Get
                Return m_id
            End Get
            Set(value As Integer)
                m_id = value
                NotifyPropertyChanged("Id")
            End Set
        End Property
        Private m_name As String
        Public Property Name As String
            Get
                Return m_name
            End Get
            Set(value As String)
                m_name = value
                NotifyPropertyChanged("Name")
            End Set
        End Property
     
        Private m_info As Integer
        Public Property Info As Integer
            Get
                Return m_info
            End Get
            Set(value As Integer)
                m_info = value
                NotifyPropertyChanged("Info")
            End Set
        End Property
     
      End Class
     
     
     
    Imports System.Collections.ObjectModel
    Imports System.ComponentModel
    Public Class MainModel
        Inherits BaseItem
        Public Sub New()
            m_currentPage = 0
            m_currentSize = 2
            FirstPage = New MyCommand(AddressOf OnFirstPage, AddressOf CanPage)
            PrevPage = New MyCommand(AddressOf OnPrevPage, AddressOf CanPage)
            NextPage = New MyCommand(AddressOf OnNextPage, AddressOf CanPage)
            LastPage = New MyCommand(AddressOf OnLastPage, AddressOf CanPage)
            LoadItems()
        End Sub
        Private m_currentPage As Integer
        Public Property CurrentPage As Integer
            Get
                Return m_currentPage
            End Get
            Set(value As Integer)
                m_currentPage = value
                NotifyPropertyChanged("CurrentPage")
            End Set
        End Property
        'taille de page = 2 => affiche 2 rectifiers /page
        Private m_currentSize As Integer
        Public Property CurrentSize As Integer
            Get
                Return m_currentSize
            End Get
            Set(value As Integer)
                m_currentSize = value
                NotifyPropertyChanged("CurrentSize")
            End Set
        End Property
        'nouveauté :l'element selection est un ObservableCollection(Of Item)
        ' le chevron Xaml slash "/" permettra d'acceder à chaque field du "rectifier" sous-selectionné
        Private m_selectedList As ObservableCollection(Of Item)
        Public Property SelectedList As ObservableCollection(Of Item)
            Get
                Return m_selectedList
            End Get
            Set(value As ObservableCollection(Of Item))
                m_selectedList = value
                NotifyPropertyChanged("SelectedList")
            End Set
        End Property
        Private m_items As ObservableCollection(Of ObservableCollection(Of Item))
        Public Property Items As ObservableCollection(Of ObservableCollection(Of Item))
            Get
                Return m_items
            End Get
            Set(value As ObservableCollection(Of ObservableCollection(Of Item)))
                m_items = value
                NotifyPropertyChanged("Items")
                NotifyPropertyChanged("Page")
            End Set
        End Property
        Private m_page As ObservableCollection(Of ObservableCollection(Of Item))
        Public Property Page As ObservableCollection(Of ObservableCollection(Of Item))
            Get
                Return m_page
            End Get
            Set(value As ObservableCollection(Of ObservableCollection(Of Item)))
                m_page = value
                NotifyPropertyChanged("Page")
            End Set
        End Property
     
     
     
     
        Private Sub LoadItems()
            Dim r As New Random
            Dim numero As Integer = 1
            Dim arr(7, 3) As Item
     
            For i As Integer = 0 To arr.GetUpperBound(0)
                For j As Integer = 0 To arr.GetUpperBound(1)
                    Dim it As New Item() With {.Id = numero, .Name = "Item" + numero.ToString, .Info = r.Next(50, 150)}
                    arr(i, j) = it
                    numero += 1
                    If j = 3 Then numero -= 1
                Next
                numero += 1
            Next
     
            m_items = New ObservableCollection(Of ObservableCollection(Of Item))
            For i As Integer = 0 To arr.GetUpperBound(0)
                m_items.Add(New ObservableCollection(Of Item))
                For j As Integer = 0 To arr.GetUpperBound(1)
                    m_items.Item(i).Add(arr(i, j))
                Next
            Next
        End Sub
     
        'commandes de navigation de page
        Public Property FirstPage As MyCommand
        Public Property PrevPage As MyCommand
        Public Property NextPage As MyCommand
        Public Property LastPage As MyCommand
        Private Sub OnFirstPage()
            CurrentPage = 0
            Paging(CurrentPage, CurrentSize)
        End Sub
     
        Private Sub OnPrevPage()
            CurrentPage = If((CurrentPage - 1) > 0, (CurrentPage - 1), 0)
            Paging(CurrentPage, CurrentSize)
        End Sub
     
        Private Sub OnNextPage()
            CurrentPage = If((CurrentPage + 1) * CurrentSize < Items.Count(),
                   (CurrentPage + 1), CurrentPage)
            Paging(CurrentPage, CurrentSize)
        End Sub
     
     
        Private Sub OnLastPage()
            CurrentPage = (Items.Count / CurrentSize) - 1
            Paging(CurrentPage, CurrentSize)
        End Sub
        ' commandes toujours activées c.à.d all buttons enabled
        Private Function CanPage() As Boolean
            Return True
        End Function
        'method de saut de pafe qui tient de la taille de page 
        Public Sub Paging(pagenum As Integer, pagesize As Integer)
     
            If (CurrentPage < 0) Then
                CurrentPage = 0 : Return
            End If
            Dim query = From p In Items.Skip(pagenum * pagesize).Take(pagesize)
                               Select New With {.elem = p}
     
            Page = New ObservableCollection(Of ObservableCollection(Of Item))
            For Each obj In query.ToList()
                Page.Add(obj.elem)
            Next
     
        End Sub
     
    End Class
    2/ class command:
    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
    Public Class MyCommand
        Implements ICommand
     
        Private m_canExecute As Func(Of Boolean)
        Private m_executeAction As Action(Of Object)
     
        Public Sub New(ByVal executeAction As Action(Of Object), ByVal canExecute As Func(Of Boolean))
            Me.m_executeAction = executeAction
            Me.m_canExecute = canExecute
        End Sub
        Public Function CanExecute(ByVal parameter As Object) As Boolean Implements ICommand.CanExecute
            If (m_canExecute IsNot Nothing) Then
                Return m_canExecute()
            End If
     
            If (m_executeAction IsNot Nothing) Then
                Return True
            End If
     
            Return False
        End Function
     
        Public Sub Execute(ByVal parameter As Object) Implements ICommand.Execute
            m_executeAction(parameter)
        End Sub
     
        Public Custom Event CanExecuteChanged As EventHandler Implements System.Windows.Input.ICommand.CanExecuteChanged
            AddHandler(value As EventHandler)
                AddHandler CommandManager.RequerySuggested, value
            End AddHandler
            RemoveHandler(ByVal value As EventHandler)
                RemoveHandler CommandManager.RequerySuggested, value
            End RemoveHandler
     
            RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)
                CanExecute(sender)
            End RaiseEvent
        End Event
        Public Sub RaiseCanExecuteChanged()
            RaiseEvent CanExecuteChanged(Me, EventArgs.Empty)
        End Sub
    End Class

    3/ class Application (pour les resources)
    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
    <Application x:Class="Application"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfPager"
        StartupUri="Test.xaml">
        <Application.Resources>
            <Style x:Key="HorizontalListBox">
                <Setter Property="ListBox.ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <DataTemplate x:Key="CellTemplate"
                          DataType="{x:Type local:Item}">
                <Border BorderThickness="2" BorderBrush="DarkGray" 
                   CornerRadius="2"  >
                    <StackPanel Orientation="Horizontal">
                        <Button Margin="5"  Content="Show" Foreground="Maroon"/>
                        <TextBlock Margin="5" Text="{Binding Id}"/>
                        <TextBlock Margin="5" Text="{Binding Name}"/>
                        <TextBlock Margin="5" Text="{Binding Info}"/>
                    </StackPanel>
     
                </Border>
            </DataTemplate>
            <DataTemplate x:Key="RowTemplate">
                <ListBox 
                    IsSynchronizedWithCurrentItem="True"
                    ItemsSource="{Binding }"
                    Style="{StaticResource HorizontalListBox}" 
                    ItemTemplate="{StaticResource CellTemplate}" 
                    >
                </ListBox>
            </DataTemplate>
        </Application.Resources>
    </Application>
    4/ Form user de test(pas de code behind) :

    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
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    <Window x:Class="Test"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfPager" 
        Title="Test" Height="350" Width="525">
        <Window.DataContext>
            <local:MainModel/>
        </Window.DataContext>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"></RowDefinition>
                <RowDefinition ></RowDefinition>
                <RowDefinition ></RowDefinition>
            </Grid.RowDefinitions>
            <StackPanel 
                Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" 
                Orientation="Horizontal"
                HorizontalAlignment="Center">
                <Label Content="{Binding CurrentPage}" FontSize="14" FontWeight="Bold"/>
                <Button Content="FirstPage" Margin="5" Command="{Binding FirstPage}" Foreground="Black" Background="Khaki" FontSize="16"/>
                <Button Content="PrevPage" Margin="5"   Command="{Binding PrevPage}" Foreground="Black" Background="Khaki" FontSize="16"/>
                <Button Content="NextPage" Margin="5"   Command="{Binding NextPage}" Foreground="Black" Background="Khaki" FontSize="16"/>
                <Button Content="LastPage" Margin="5"   Command="{Binding LastPage}" Foreground="Black" Background="Khaki" FontSize="16"/>
            </StackPanel>
            <!--le listbox lbSource est affiché pour voir que les  modifications(update des fields) de la collection Page-->
            <!--sont repercutés dans la collection Items source -->
            <!--les ajouts et suppressions doivent se faire directement dans la collection source -->
     
            <StackPanel 
                Grid.Row="1" Grid.RowSpan="2"  Grid.Column="0">
                <Label Content="Liste Origine Pour Illustration" 
                       FontWeight="Bold" FontSize="14" 
                       Foreground="Maroon" Background="LightGray"/>
                <ListBox
                x:Name="lbSource"
                ItemsSource="{Binding Items}"
                ItemTemplate="{StaticResource RowTemplate}" 
                SelectedItem="{Binding Path=SelectedList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                </ListBox>
            </StackPanel>
     
     
            <!--attention-->
            <StackPanel
                Grid.Row="1" Grid.Column="1">
                <Label Content="Afficher Page" 
                       FontWeight="Bold" FontSize="14" 
                       Foreground="Maroon" Background="LightGray"/>
                <ListBox
                    x:Name="lbpage"
     
                    IsSynchronizedWithCurrentItem="True"
                    ItemsSource="{Binding Page}"
                    ItemTemplate="{StaticResource RowTemplate}"
                    SelectedItem="{Binding Path=SelectedList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                </ListBox>
            </StackPanel>
     
            <StackPanel 
                Grid.Row="2" Grid.Column="1"   >
                <Label Content="Saisie=>SELECT List THEN  Rectifier" 
                       HorizontalAlignment="Center"
                       FontWeight="Bold" FontSize="14" 
                       Foreground="Maroon" Background="LightGray"/>
                <TextBox   Text="{Binding Path=SelectedList/Id}"/>
                <TextBox   Text="{Binding Path=SelectedList/Name}"/>
                <TextBox   Text="{Binding Path=SelectedList/Info}"/>
            </StackPanel>
        </Grid>
    </Window>
    bon code....

  15. #15
    Membre averti Avatar de megamario
    Homme Profil pro
    VB6/VB.net/C/C++/C#
    Inscrit en
    Septembre 2008
    Messages
    928
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : VB6/VB.net/C/C++/C#
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2008
    Messages : 928
    Points : 312
    Points
    312
    Par défaut
    Bonjour MABROUKI,

    Un grand merci à vous, je viens de monter votre exemple, il fonctionne parfaitement et j'ai commencé à regarder son fonctionnement, j'ai pas tout digérer encore, mais j'ai retrouvé ce que j'avais vu dans d'autre exemple que je n'arrivais pas à adapter.

    Merci beaucoup. Je ne vais pas l’adapter tout de suite, car ma bidouille fonctionne pour le moment et je dois avancer, mais un grand merci, car j'en rêvais la nuit de ce problème et je vais enfin pouvoir comprendre.
    J'ai demandé une formation WPF, accepté par ma hiérarchie, mais impossible de trouver une formation. Tous ceux que j'ai demandé n'avait pas assez de personne pour lancer le projet de formation. C'est agaçant, car il me manque des bases...

    Voila un scan d’écran de ce que j'ai fait:
    Nom : RectifierPlant3.png
Affichages : 346
Taille : 50,3 Ko



    J'ai ajouté les 4 boutons de navigation, mais aussi 4 boutons (raccourci sur la page directement) en forme de petit cercle au centre bas, indiquant la page sélectionnée grâce à la bordure cerclé de noir, et au background changeant de couleur, gris clair (Pas de redresseur présent dans la page), Vert (Redresseur(s) présent), Rouge (Redresseur(s) en alarme).

    Pour l’interrogation avec l'automate, le protocole de communication me permet de récupérer un objet synthétisant les redresseurs installés et en défauts (Des gros bitfield m'indiquant si la position est active ou pas parmi les 120), cela me permet de ne pas avoir à interroger les 120 objets pour les 120 redresseurs. Donc ensuite j’interroge uniquement les objets "redresseur" s'ils sont installé et visible sur la page en cours, mais l'utilisateur peut voir si sur l'une des pages il y a des redresseurs ou s'il y en a en défaut, sans voir à passer en revu chaque page.

Discussions similaires

  1. [Debutant] - WPF MVVM Binding XML in Treeview
    Par Ganeshiva dans le forum Windows Presentation Foundation
    Réponses: 0
    Dernier message: 29/03/2017, 11h27
  2. WPF MVVM binding Contextmenu sur ListboxItem
    Par gurcan dans le forum C#
    Réponses: 0
    Dernier message: 10/06/2016, 13h43
  3. [Débutant] WPF MVVM Afficher Message a l'utilisateur
    Par draco951 dans le forum C#
    Réponses: 2
    Dernier message: 05/02/2013, 11h10
  4. WPF MVVM Binding Refresh
    Par gridin dans le forum Windows Presentation Foundation
    Réponses: 7
    Dernier message: 14/01/2011, 11h26
  5. Binding entre 2 contrôles WPF
    Par mascoco dans le forum Windows Presentation Foundation
    Réponses: 5
    Dernier message: 28/06/2010, 17h51

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