我正在尝试将动态内容绑定到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
发布评论