在本地计算机上,此代码有效:
视图模型:
Public Class TestViewModel
Implements INotifyPropertyChanged
Public ReadOnly Property ReturnParam(Param As String) As String
Get
Return Param
End Get
End Property
Public ReadOnly Property SimpleProperty() As String
Get
Return "World!!!"
End Get
End Property
Public Sub RaisePropertyChanged(PropertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PropertyName))
End Sub
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
End Class
的Xaml:
<Window.Resources>
<local:TestViewModel x:Key="vm" />
</Window.Resources>
<Grid DataContext="{StaticResource vm}">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path=ReturnParam[Hello]}" />
<Label Content="{Binding Path=SimpleProperty}" />
</StackPanel>
</Grid>
结果:
另一台电脑上有:
我在.NET 4.0中遇到此问题,使用.NET 4.5此代码适用于任何计算机。 我做错了什么?