WP7备注(40)(TemplatePart)
2011-05-10 12:20 血糯米Otomii 阅读(453) 评论(0) 编辑 收藏 举报TemplatePart的作用是*.cs中对于*.xaml中定义的控件进行获取,并进行操作
[TemplateVisualStateAttribute(Name = "Normal", GroupName = "CommonStates")] [TemplateVisualStateAttribute(Name = "MouseOver", GroupName = "CommonStates")] [TemplateVisualStateAttribute(Name = "Disabled", GroupName = "CommonStates")] [TemplateVisualStateAttribute(Name = "Focused", GroupName = "FocusStates")] [TemplateVisualStateAttribute(Name = "Unfocused", GroupName = "FocusStates")] [TemplatePartAttribute(Name = "HorizontalTemplate", Type = typeof(FrameworkElement))] [TemplatePartAttribute(Name = "HorizontalTrackLargeChangeDecreaseRepeatButton", Type = typeof(RepeatButton))] [TemplatePartAttribute(Name = "HorizontalTrackLargeChangeIncreaseRepeatButton", Type = typeof(RepeatButton))] [TemplatePartAttribute(Name = "HorizontalThumb", Type = typeof(Thumb))] [TemplatePartAttribute(Name = "VerticalTemplate", Type = typeof(FrameworkElement))] [TemplatePartAttribute(Name = "VerticalTrackLargeChangeDecreaseRepeatButton", Type = typeof(RepeatButton))] [TemplatePartAttribute(Name = "VerticalTrackLargeChangeIncreaseRepeatButton", Type = typeof(RepeatButton))] [TemplatePartAttribute(Name = "VerticalThumb", Type = typeof(Thumb))] public class Slider : RangeBase
<phone:PhoneApplicationPage.Resources> <ControlTemplate x:Key="bareBonesSliderTemplate" TargetType="Slider"> <Grid> <Grid Name="HorizontalTemplate"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <RepeatButton Name="HorizontalTrackLargeChangeDecreaseRepeatButton" Grid.Column="0" Content="-" /> <Thumb Name="HorizontalThumb" Grid.Column="1" /> <RepeatButton Name="HorizontalTrackLargeChangeIncreaseRepeatButton" Grid.Column="2" Content="+" /> </Grid> <Grid Name="VerticalTemplate"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <RepeatButton Name="VerticalTrackLargeChangeDecreaseRepeatButton" Grid.Row="0" Content="-" /> <Thumb Name="VerticalThumb" Grid.Row="1" /> <RepeatButton Name="VerticalTrackLargeChangeIncreaseRepeatButton" Grid.Row="2" Content="+" /> </Grid> </Grid> </ControlTemplate> </phone:PhoneApplicationPage.Resources>
public override void OnApplyTemplate() { base.OnApplyTemplate(); //获取TemplateApart控件 }