WPF TwoWay Binding to a static class Property

前端 未结 3 2150
遥遥无期
遥遥无期 2020-12-01 20:25

There\'s no problem if Mode=OneWay, but I have this: Class:

namespace Halt
{
    public class ProjectData
    {
            public static string Username {ge         


        
3条回答
  •  暖寄归人
    2020-12-01 20:38

    Use the static property binding syntax (which is, as far as I know, available since WPF 4.5):

    
    

    No need to set Mode="TwoWay", as that is the default for the TextBox.Text property anyway.


    Although not explicitly asked for, you may also want to implement property change notification.

    See this answer for how to do it.

提交回复
热议问题