XAML TextBox绑定到Class内的Property

时间:2014-06-17 16:04:00

标签: vb.net xaml windows-phone-8.1

好的,所以我试图在Windows Phone应用程序中设置一个页面,该页面将有一个包含2个组的LongListSelector,并且在每个组中都有可以显示的不同类型的数据。我能够设置一个TemplateSelector,为不同类型的对象选择正确的数据模板,但我似乎无法深入到数据源中实际值的正确绑定路径。我会尝试发布所有相关代码,看看是否有帮助

    'These are the classes that are used for the Datasource, there are 2 specific classes and then one class to use for the data source that will contain a type value and then one of the 2 specific classes
 Public Class ActionItemsClass
        Public Property type As String
        Public Property alertItem As AlertClass
        Public Property btrItem As BTRClass
    End Class

    Public Class AlertClass
        Public Property asOfDate As String
        Public Property subject As String
        Public Property text As String

    End Class

    Public Class BTRClass
        Public Property id As String
        Public Property policyID As String
        Public Property fromUser As String
        Public Property txnNumber As String
        Public Property createdDate As String
        Public Property contactID As String
        Public Property contactName As String
        Public Property productName As String
        Public Property investmentAmount As String
        Public Property btrNote As String
        Public Property currentStatus As String
        Public Property response As String

    End Class

这里是模板选择的XAML代码,正如您所看到的,我已经尝试了各种方法来显示数据(现在每个类只有一个项目作为测试)但到目前为止唯一显示的是组头和数据源正在创建而没有任何问题

<DataTemplate x:Key="alertItem">
            <TextBlock DataContext="{Binding AlertClass}" Text="{Binding text}" Foreground="Red"/>
        </DataTemplate>
        <DataTemplate x:Key="btrItem">
            <TextBlock Text ="{Binding Path=btrItem.btrNote}" Foreground="Green"/>
        </DataTemplate>
        <DataTemplate x:Key="SelectingTemplate">
            <local:TemplateSelector AlertTemplate ="{StaticResource alertItem}"
                                    BTRTemplate="{StaticResource btrItem}"/>

1 个答案:

答案 0 :(得分:0)

我认为你需要像这样绑定文本块

<TextBlock Text="{Binding AlertClass.text}" Foreground="Red"/>