0

I created a WPF Window with a StatusBar. I tried to create a method to update the Statusbar Text with a Buttom from another form:

    public static void setSbStatus(string ComPort)
    {
        setSbStatus.Text = clsVariables.strSelectCom;

    }

But Visual Studio throws error CS0199. How can I access the statusbar from another form?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Basti An
  • 347
  • 1
  • 6
  • 23

1 Answers1

0

setSbStatus is the name of the method you are trying to set the text property from. Do you have a name for the status bar? Assuming you are declaring it from XAML, make sure you have set the name of the element like this: x:Name="sbStatus".

Then you can can change your code to this:

sbStatus.Text = clsVariables.strSelectCom;

One more point: you are using a static method to set a property of a non-static member (UI element). You can only call a static function from another static or non-static function, but not the other way around.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Slime recipe
  • 2,223
  • 3
  • 32
  • 49
  • This is how it is in my XAML: But I cant put sbStatus.text in my function that I want to use to Change the text: public static void setSbStatus(string ComPort) { setSbStatus.Text = clsVariables.strSelectCom; } This throws error CS0119 – Basti An Aug 29 '15 at 16:12
  • I assume you are coming from a different languege. setSbStatus.Text is an invalid statment in the context you are trying to use because what you are doing is stating that the Text member of the method should be set to XYZ. c# dose not support "function members" if you will. – Slime recipe Aug 29 '15 at 16:24
  • I updated my post to better reflect your XAML / varible naming. – Slime recipe Aug 29 '15 at 16:25