将动态数据绑定到ToggleSwitch.ContentTemplate

编程入门 行业动态 更新时间:2024-10-10 21:25:36
本文介绍了将动态数据绑定到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:

msdn.microsoft/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

本文发布于:2023-08-03 12:40:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   动态   数据   ContentTemplate   ToggleSwitch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!