What's the process of binding to a static variable? RRS feed

  • Question

  • I've tried to google this but all I find are people asking very specific questions on the subject, not an explanation of how to do it.

    Let's say I have a class called UserOptions, in it are three static bool properties. I want to bind three radiobuttons to those properties.

    Could someone delineate the steps necessary to do that please?


    Edit: This is in WPF.
    • Edited by Integrater Monday, January 20, 2020 4:11 PM
    Sunday, January 19, 2020 1:40 PM


All replies

  • Are you talking about Windows Forms here?  Have you tried doing it exactly like you would with a non-static property?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Sunday, January 19, 2020 8:39 PM
  • Hi Intefrater,

    Thank you for posting here.

    Check the code below to see if it is what you want.

       class MyClass
            public static bool first = false;
            public static bool second = true;
        private void Form1_Load(object sender, EventArgs e)
             radioButton1.Checked = MyClass.first;
             radioButton2.Checked = MyClass.second;

    It works for Windows Forms App.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 20, 2020 6:27 AM
  • My apologies! I totally forgot to say this is in C#/WPF.
    Monday, January 20, 2020 11:39 AM
  • This seems to address what you want.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by Integrater Tuesday, January 21, 2020 2:25 PM
    Tuesday, January 21, 2020 2:43 AM