1 回答
TA贡献1843条经验 获得超7个赞
您可以使用 WPF 数据绑定:
无需使用 更改它if,只需绑定 XAML 接口并更改类上的属性即可。
Imports System.ComponentModel
Public Class Class1
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private _ModeSta1 As Boolean
Property ModeSta1 As Boolean
Get
Return _ModeSta1
End Get
Set(ByVal value As Boolean)
_ModeSta1 = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(ModeSta1)))
End Set
End Property
End Class
将 CheckBox 更改为仅绑定到ModeSta1属性
<CheckBox x:Name="ckbx1"
Content=" Input"
Margin="99.866,78.932,0,0"
VerticalAlignment="Top"
HorizontalAlignment="Left"
IsChecked="{Binding Path=ModeSta1, Mode=TwoWay}"
/>
当 的值ModeSta1改变时,用户界面会更新,如果用户点击复选框,ModeSta1值也会改变。
Dim c = New Class1
DataContext = c
' You can change the property and this change will be visible on the UI
c.ModeSta1 = True
- 1 回答
- 0 关注
- 355 浏览
添加回答
举报