好的...我是一个 VB.NET WinForms 人,试图了解 WPF 及其所有精彩。我正在编写一个基本的应用程序作为学习经验,并且一直在阅读大量信息并观看教程视频,但是我无法通过简单的 DataBinding 起步,而且我知道我缺少一些基本概念。尽管我很喜欢它,但我没有那个“啊哈!” 审查源代码的那一刻。
所以...在我的 Window 类中,我定义了一个自定义字符串属性。当我进入 Blend 时,我尝试将我的 TextBox 的文本数据绑定到这个属性,但我的属性在 Blend 中没有显示为可用于绑定的东西。
有人可以告诉我我需要在下面的代码/XAML 中添加什么……最重要的是为什么?
我的 XAML:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBox Text="How do I Bind my SomeText property here?"></TextBox>
</Grid>
</Window>
我的窗口代码:
Class Window1
Private _sometext As String = "Hello World"
Public Property SomeText() As String
Get
Return _sometext
End Get
Set(ByVal value As String)
_sometext = value
End Set
End Property
End Class