这篇文章主要介绍了高仿Windows Phone QQ登录界面实例代码,有需要的朋友可以参考一下
给 TextBox文本框前添加图片 扩展PhoneTextBox:添加一个类“ExtentPhoneTextBox”继承 PhoneTextBox ,在“ExtentPhoneTextBox”类中添加属性项: 代码如下: public class ExtentPhoneTextBox : PhoneTextBox { /// <summary> /// 文本框图片属性 /// </summary> public static readonly DependencyProperty TextHeadImageProperty = DependencyProperty.Register("TextHeadImage", typeof(ImageSource), typeof(ExtentPhoneTextBox), new PropertyMetadata(null) ); /// <summary> /// 文本框头图片 /// </summary> public ImageSource TextHeadImage { get { return base.GetValue(TextHeadImageProperty) as ImageSource; } set { base.SetValue(TextHeadImageProperty, value); } } /// <summary> /// 文本图片宽度 /// </summary> public double TextHeadImageWidth { get { return (double)GetValue(TextHeadImageWidthProperty); } set { SetValue(TextHeadImageWidthProperty, value); } } // Using a DependencyProperty as the backing store for TextHeadImageWidth. This enables animation, styling, binding, etc... public static readonly DependencyProperty TextHeadImageWidthProperty = DependencyProperty.Register("TextHeadImageWidth", typeof(double), typeof(ExtentPhoneTextBox), new PropertyMetadata(null)); /// <summary> /// 文本图片高度 /// </summary> public double TextHeadImageHeight { get { return (double)GetValue(TextHeadImageHeightProperty); } set { SetValue(TextHeadImageHeightProperty, value); } } // Using a DependencyProperty as the backing store for TextHeadImageHeight. This enables animation, styling, binding, etc... public static readonly DependencyProperty TextHeadImageHeightProperty = DependencyProperty.Register("TextHeadImageHeight", typeof(double), typeof(ExtentPhoneTextBox), new PropertyMetadata(null)); } } 全部样式如下: 复制代码 代码如下: <DataTemplate x:Key="ControlHeaderTemplate"> <TextBlock FontSize="{StaticResource PhoneFontSizeNormal}" FontFamily="{StaticResource PhoneFontFamilyNormal}" LineStackingStrategy="BlockLineHeight" LineHeight="23.333" Margin="0,-9,0,0" TextWrapping="Wrap" Text="{Binding}"> <TextBlock.RenderTransform> <TranslateTransform X="-1" Y="4"/> </TextBlock.RenderTransform> </TextBlock> </DataTemplate> <toolkit:SingleDataTemplateSelector x:Key="ControlHeaderTemplateSelector" Template="{StaticResource ControlHeaderTemplate}"/> <Style x:Key="ExtentPhoneTextBoxStyle" TargetType="ExtentCtrs:ExtentPhoneTextBox"> <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/> <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> <Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/> <Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/> <Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/> <Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/> <Setter Property="SelectionForeground" Value="{StaticResource PhoneTextBoxSelectionForegroundBrush}"/> <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> <Setter Property="Padding" Value="6,0,6,4"/> <Setter Property="HorizontalContentAlignment" Value="Left"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ExtentCtrs:ExtentPhoneTextBox"> <Grid x:Name="RootGrid" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition/> </Grid.RowDefinitions> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"/> <VisualState x:Name="Disabled"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Header">