Windows 10 个通用应用程序已编译绑定/x:bind 不工作
Windows 10 Universal App compiled Bindings / x:bind not working
我有以下代码来测试通用 Windows 10 个应用程序中的新编译绑定。
XAML:
<Page
x:Class="xBindTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:xBindTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="Tester" Text="{x:Bind myBindClass.TestText, Mode=OneWay}" ></TextBlock>
<TextBlock x:Name="Tester2" Text="{Binding myBindClass.TestText, Mode=OneWay}" ></TextBlock>
<Button x:Name="button" Content="Button" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</StackPanel>
</Grid>
隐藏代码:
Public Class xBindClass : Implements INotifyPropertyChanged
Private _TestText As String
Public Property TestText As String
Get
Return _TestText
End Get
Set(value As String)
If _TestText <> value Then
_TestText = value
NotifyPropertyChanged("TestText")
End If
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(<CallerMemberName> Optional propertyName As String = "")
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
''' <summary>
''' An empty page that can be used on its own or navigated to within a Frame.
''' </summary>
Public NotInheritable Class MainPage
Inherits Page
Public Property myBindClass As xBindClass
Public Sub New()
' Add any initialization after the InitializeComponent() call.
myBindClass = New xBindClass With {.TestText = "Hello"}
' This call is required by the designer.
InitializeComponent()
End Sub
Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
myBindClass.TestText &= " There"
Tester.DataContext = myBindClass.TestText
End Sub
End Class
我正在并排测试这两种绑定类型...标准 {Binding...} 类型工作正常,但新的 x:Bind 工作不正常...
也许我误解了新绑定的工作原理?但我明白,x:Bind 绑定到 CodeBehind,所需要的只是绑定到 public 属性,然后你就关闭了 运行.
我正在使用 VS2015 RC 和 Win 10 build 10130。
原来 x:bind
没有在 vb.net 中实现,因为 VS2015RC.MS 已经确认这将在完整的 RTM
中实现
我有以下代码来测试通用 Windows 10 个应用程序中的新编译绑定。
XAML:
<Page
x:Class="xBindTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:xBindTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="Tester" Text="{x:Bind myBindClass.TestText, Mode=OneWay}" ></TextBlock>
<TextBlock x:Name="Tester2" Text="{Binding myBindClass.TestText, Mode=OneWay}" ></TextBlock>
<Button x:Name="button" Content="Button" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</StackPanel>
</Grid>
隐藏代码:
Public Class xBindClass : Implements INotifyPropertyChanged
Private _TestText As String
Public Property TestText As String
Get
Return _TestText
End Get
Set(value As String)
If _TestText <> value Then
_TestText = value
NotifyPropertyChanged("TestText")
End If
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(<CallerMemberName> Optional propertyName As String = "")
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
''' <summary>
''' An empty page that can be used on its own or navigated to within a Frame.
''' </summary>
Public NotInheritable Class MainPage
Inherits Page
Public Property myBindClass As xBindClass
Public Sub New()
' Add any initialization after the InitializeComponent() call.
myBindClass = New xBindClass With {.TestText = "Hello"}
' This call is required by the designer.
InitializeComponent()
End Sub
Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
myBindClass.TestText &= " There"
Tester.DataContext = myBindClass.TestText
End Sub
End Class
我正在并排测试这两种绑定类型...标准 {Binding...} 类型工作正常,但新的 x:Bind 工作不正常...
也许我误解了新绑定的工作原理?但我明白,x:Bind 绑定到 CodeBehind,所需要的只是绑定到 public 属性,然后你就关闭了 运行.
我正在使用 VS2015 RC 和 Win 10 build 10130。
原来 x:bind
没有在 vb.net 中实现,因为 VS2015RC.MS 已经确认这将在完整的 RTM