2013-07-07 36 views
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> 

回答

1

在你的情况,我不明白为什么你甚至懒得为ToggleSwitch设置ContentTemplate,因为没有自定义绑定存在(例如一个特定实例的集合)。

相反,直接设置内容并以同样的方式修改TimePicker属性 - 通过命名引用。

附注:为什么你还要在ToggleSwitch里面有TimePicker

+0

好的,这是我怀疑为什么它需要在第一次的例子ContentTemplate。我试图移除但效果不佳。但现在我再次做到了,而且没有问题。谢谢!哦,我把timePicker放在ToggleSwitch里的原因是我想把timepicker和拨动开关的文本对齐。有点愚蠢,但为我工作:) – thsieh

相关问题