salut à tous

comme souvent, je vais faire appel à vos lumières sur un truc, à mon avis basique pour les spécialistes que vous êtes, mais qui me coûte des cheveux depuis un moment!
je viens d'arriver sur un projet que je découvre (C# aussi), mais que j'essaye déjà d'améliorer...


en gros:
-> commands.xaml.cs: gestion d'un textblock (InfoSysZone) et de la méthode d'affichage d'informations (InfoSysy()), en append de l'existant: fonctionne parfaitement
-> selection.xaml.cs: appel de la méthode pour affichage d'un message

problème:
en l'état mettre l'appel à InfoSys() est impossible dans selection.xaml.cs

-> InfoSys("Message 1", 2); error CS0103: Le nom 'InfoSys' n'existe pas dans le contexte actuel
(logique)

-> commands.InfoSys("Message 1", 2); error CS0120: Une référence d'objet est requise pour la propriété, la méthode ou le champ non statique 'Commands.InfoSys(string, int)'
(logique, InfoSys() n'étant pas static)

mais en passant InfoSys() en static dans commands.xaml.cs
-> public static void InfoSys(string msg, int cr) error CS0120: Une référence d'objet est requise pour la propriété, la méthode ou le champ non statique 'Commands.InfoSysZone'


donc, comment faire pour utiliser InfoSys() en dehors de commands.xaml.cs?

toute aide sera appréciée...
merci

commands.xaml.cs
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
using System.Windows.Controls;
 
namespace ProjectGUI.View
{
    /// <summary>
    /// Logique d'interaction pour Commands.xaml
    /// </summary>
    public partial class Commands : UserControl
    {
        public Commands()
        {
            InitializeComponent();
            InfoSys("Message 1", 2);
            InfoSys("Message 2", 1);
            InfoSys("Message 3", 1);
        }
 
        //public static void InfoSys(string msg, int cr)
        public void InfoSys(string msg, int cr)
        {
            InfoSysZone.Text += msg;
            for (int i=0; i<cr; i++)
            {
                InfoSysZone.Text += "\r\n";
            }
        }
    }
}
selection.xaml.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ProjectGUI.View
{
    /// <summary>
    /// Logique d'interaction pour Selection.xaml
    /// </summary>
    public partial class Selection : UserControl
    {
        public Selection()
        {
            InitializeComponent();
            => appeler InfoSys(); ici
        }
       
    }
}