作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
Possible Duplicate:
Data Binding WPF Property to Variable
如何将我的 module1 属性绑定(bind)到我的 WPF TextBox1?
WPF代码:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox Height="23" HorizontalAlignment="Left" Margin="210,146,0,0" Name="TextBox1" VerticalAlignment="Top" Width="120" />
</Grid>
</Window>
VB.net 代码:
Module Module1
ReadOnly Property tbBinding As String
Get
Return "Success!"
End Get
End Property
End Module
下面是我根据收到的反馈和我一直在做的阅读所做的代码。/#######Current code in progres (try with a class instead of a module)#######/
XAML:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid DataContext="Class1">
<TextBox Height="23" HorizontalAlignment="Left" Margin="210,146,0,0" Name="TextBox1" VerticalAlignment="Top" Width="120" Text="{Binding Path=tbBinding2}"/>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="192,74,0,0" Name="Button1" VerticalAlignment="Top" Width="75" />
</Grid>
</Window>
第 1 类:
Imports System.ComponentModel
Public Class Class1
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Dim varField As String = String.Empty
Public Property tbBinding2 As String
Get
Return varField
End Get
Set(value As String)
varField = value
NotifyPropertyChanged("tbBinding2")
End Set
End Property
End Class
主窗口:
Class MainWindow
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim myClass1 As New Class1
myClass1.tbBinding2 = "Success!"
End Sub
End Class
我是一名优秀的程序员,十分优秀!