0
我已经定义了4个ToggleSwitch(从示例复制)。我必须使用DataTemplate吗?现在我想在TimePicker中更改时间值。如何访问time_picker并更改内容?非常感谢!Windows Phone:如何从C#代码中更改TimePicker中的时间
<toolkit:ToggleSwitch Name="sleep_mode" Grid.Row="1" Header="{Binding Path=LocalizedResources.Sleep_Mode, Source={StaticResource LocalizedStrings}}" Checked="fetch_sleepmode_Checked" Unchecked="fetch_sleepmode_UnChecked" Click="OnClicked">
<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="{Binding Path=LocalizedResources.Status, Source={StaticResource LocalizedStrings}}" FontSize="{StaticResource PhoneFontSizeSmall}"/>
<ContentControl HorizontalAlignment="Left" FontSize="{StaticResource PhoneFontSizeSmall}" Content="{Binding}"/>
</StackPanel>
<TextBlock Text="{Binding Path=LocalizedResources.SleepMode, Source={StaticResource LocalizedStrings}}" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeSmall}" Foreground="{StaticResource PhoneSubtleBrush}" Width="360"/>
**<toolkit:TimePicker x:Name="time_picker" ValueChanged="TimePicker_ValueChanged"/>**
</StackPanel>
</DataTemplate>
</toolkit:ToggleSwitch.ContentTemplate>
</toolkit:ToggleSwitch>
好的,这是我怀疑为什么它需要在第一次的例子ContentTemplate。我试图移除但效果不佳。但现在我再次做到了,而且没有问题。谢谢!哦,我把timePicker放在ToggleSwitch里的原因是我想把timepicker和拨动开关的文本对齐。有点愚蠢,但为我工作:) – thsieh