如何在绑定时正确使用路径参数。 {Binding Path = AnyProperty [indexer]}

时间:2014-05-12 08:57:40

标签: .net wpf vb.net binding .net-4.0

在本地计算机上,此代码有效:

视图模型:

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>

结果:

enter image description here

另一台电脑上有:

enter image description here

我在.NET 4.0中遇到此问题,使用.NET 4.5此代码适用于任何计算机。 我做错了什么?

0 个答案:

没有答案