How can I best handle WPF radio buttons?

后端 未结 2 1716
借酒劲吻你
借酒劲吻你 2021-02-20 09:27

I\'ve got some RadioButtons in my XAML...


    

        
2条回答
  •  不要未来只要你来
    2021-02-20 10:02

    Better Solution using WPF MVVM Design Pattern:

    Radio Button Control XAML to Modelview.vb/ModelView.cs :

    XAML Code:
    
    
    

    ViewModel.vb :

    Private _OffJob As Boolean = False
    Private _OnJob As Boolean = False
    
    Public Property OnJob As Boolean
        Get
            Return _OnJob
        End Get
        Set(value As Boolean)
            Me._OnJob = value
        End Set
    End Property
    
    Public Property OffJob As Boolean
        Get
            Return _OffJob
        End Get
        Set(value As Boolean)
            Me._OffJob = value
        End Set
    End Property
    
    Private Sub FindCheckedItem()
      If(Me.OnJob = True)
        MessageBox.show("You have checked On")
     End If
    If(Me.OffJob = False)
     MessageBox.Show("You have checked Off")
    End sub
    

    One can use the same logic above to see if you checked any of the three Radio Buttons viz. Option One, Option Two, Option Three. But checking if the Boolean set id true or false you can identify whether the radio button is checked or not.

提交回复
热议问题