将动态数据绑定到ToggleSwitch.ContentTemplate [英] Bind dynamic data to ToggleSwitch.ContentTemplate

查看:44
本文介绍了将动态数据绑定到ToggleSwitch.ContentTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将动态内容绑定到ToggleSwitch的ContentTemplate部分。我的代码如下:

I'm trying to bind a dynamic content to the ContentTemplate section of ToggleSwitch. My code is as follows:

<toolkit:ToggleSwitch Header="{Binding LineOne}" Tap="ToggleSwitch_Tap" IsChecked="{Binding Active}">
    <toolkit:ToggleSwitch.HeaderTemplate>
        <DataTemplate>
            <ContentControl FontSize="{StaticResource PhoneFontSizeLarge}" Foreground="{StaticResource PhoneForegroundBrush}" Content="{Binding}"/>
        </DataTemplate>
    </toolkit:ToggleSwitch.HeaderTemplate>
    <toolkit:ToggleSwitch.ContentTemplate>
        <DataTemplate>
            <StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Status: " FontSize="{StaticResource PhoneFontSizeSmall}"/>
                    <ContentControl HorizontalAlignment="Left" FontSize="{StaticResource PhoneFontSizeSmall}" Content="{Binding}"/>
                </StackPanel>
                <TextBlock Text="{Binding Property}" FontSize="{StaticResource PhoneFontSizeSmall}" Foreground="{StaticResource PhoneSubtleBrush}"/>
            </StackPanel>
        </DataTemplate>
    </toolkit:ToggleSwitch.ContentTemplate>
</toolkit:ToggleSwitch>




问题在于{在ContentTemplate中的StackPanel之后的TextBlock中绑定Property}。有什么想法?

The problem is with the {Binding Property} in the TextBlock right after the StackPanel in the ContentTemplate. Any ideas?

推荐答案

以下是绑定的快速入门:

Here is a quickstart on binding:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207023(v = vs.105)的.aspx#BKMK_Displayingitemsinacontrolbyusingadatatemplate

您的问题可能是在您的来源中使用"财产"作为名称。 尝试重命名字段MyProperty。 

Your problem may be using 'Property' as a name in your source.  Try renaming the field MyProperty. 


这篇关于将动态数据绑定到ToggleSwitch.ContentTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆