技术开发 频道

Windows Phone的Silverlight Toolkit

  ToggleSwitch控件

  如果你更改过模拟器的日期/时间就可能看到过这个控件。下面是例子:

  将它添加到页面中非常简单:

<toolkit:ToggleSwitchHeader="Receive updates automatically"/>

 

  在上面的截图中写的是“24-hour clock”,我的例子将会写着“Receive updates automatically”。很幸运,On/Off文本是自动为你处理的。如果你想对这个控件做一些定制也是很简单的。我们可以利用HeaderTemplate和ContentTemplate来使这个控件更加“自我”。还有Checked和Unchecked事件,它们在操作开关时被触发。(这个控件和CheckBox很相似)。下面是一个使用示例(并绑定到了数据源):

<toolkit:ToggleSwitchHeader="12:02 AM">
<toolkit:ToggleSwitch.HeaderTemplate>
<DataTemplate>
<ContentControlFontSize="{StaticResourcePhoneFontSizeLarge}" Foreground="{StaticResourcePhoneForegroundBrush}" Content="{Binding}"/>
</DataTemplate>
</toolkit:ToggleSwitch.HeaderTemplate>
<toolkit:ToggleSwitch.ContentTemplate>
<DataTemplate>
<StackPanel>
<StackPanelOrientation="Horizontal">
<TextBlockText="Alert: " FontSize="{StaticResourcePhoneFontSizeSmall}"/>
<ContentControlHorizontalAlignment="Left" FontSize="{StaticResourcePhoneFontSizeSmall}" Content="{Binding}"/>
</StackPanel>
<TextBlockText="every weekday" FontSize="{StaticResourcePhoneFontSizeSmall}" Foreground="{StaticResourcePhoneSubtleBrush}"/>
</StackPanel>
</DataTemplate>
</toolkit:ToggleSwitch.ContentTemplate>
</toolkit:ToggleSwitch>

 

  最后是WrapPanel。它的目的很明显,因为它是标准控件集中赫然缺失的控件。

0
相关文章