wp7天氣預報源代碼(四UI的制作)視覺狀態


上一節地址:http://www.cnblogs.com/wildfeng/archive/2012/03/25/2416388.html

本次講城市列表中控件的制作。

44

image此控件為用戶自定義控件。制作布局和上一章講的ForecastTile控件一樣,只是在其基礎上增加了視覺狀態。imageimageimage

image為3個狀態添加了效果和曲線。image

控件添加的樣式生成的代碼如下:

   1:  <UserControl
   2:      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   5:      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   6:      mc:Ignorable="d"
   7:      x:Class="Weather.CityTile"
   8:      d:DesignWidth="184" d:DesignHeight="105">
   9:      <UserControl.Resources>
  10:          <Style x:Key="ButtonStyle1" TargetType="Button">
  11:              <Setter Property="Template">
  12:                  <Setter.Value>
  13:                      <ControlTemplate TargetType="Button">
  14:                          <Grid x:Name="LayoutRoot" Background="Transparent" RenderTransformOrigin="0.5,0.5"><!--變形的中心位置-->
  15:                              <Grid.RenderTransform>
  16:                                  <CompositeTransform/>
  17:                              </Grid.RenderTransform>
  18:                              <VisualStateManager.VisualStateGroups>         <!--管理器類型.狀態組-->
  19:                                  <VisualStateGroup x:Name="CommonStates">
  20:                                      <VisualStateGroup.Transitions>    <!--視覺過渡轉換,設置單個的狀態組里不同狀態切換時的動畫效果-->
  21:                                          <VisualTransition GeneratedDuration="0:0:1" To="Pressed">
  22:                                              <VisualTransition.GeneratedEasingFunction>
  23:                                                  <BackEase EasingMode="EaseOut"/>
  24:                                              </VisualTransition.GeneratedEasingFunction>
  25:                                          </VisualTransition>
  26:                                          <VisualTransition GeneratedDuration="0:0:1" To="Normal">
  27:                                              <VisualTransition.GeneratedEasingFunction>
  28:                                                  <BackEase EasingMode="EaseOut"/>
  29:                                              </VisualTransition.GeneratedEasingFunction>
  30:                                          </VisualTransition>
  31:                                          <VisualTransition GeneratedDuration="0:0:1" To="MouseOver">
  32:                                              <VisualTransition.GeneratedEasingFunction>
  33:                                                  <BackEase EasingMode="EaseOut"/>
  34:                                              </VisualTransition.GeneratedEasingFunction>
  35:                                          </VisualTransition>
  36:                                      </VisualStateGroup.Transitions>
  37:                                      <VisualState x:Name="Disabled"/>  <!--設置單個的狀態的動畫效果-->
  38:                                      <VisualState x:Name="Normal"/>    <!--設置單個的狀態的動畫效果-->
  39:                                      <VisualState x:Name="MouseOver"/>  <!--設置單個的狀態的動畫效果-->
  40:                                      <VisualState x:Name="Pressed">     <!--設置單個的狀態的動畫效果-->
  41:                                          <Storyboard>
  42:                                              <DoubleAnimation Duration="0" To="0.8" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="LayoutRoot" d:IsOptimized="True"/>
  43:                                              <DoubleAnimation Duration="0" To="0.8" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="LayoutRoot" d:IsOptimized="True"/>
  44:                                          </Storyboard>
  45:                                      </VisualState>
  46:                                  </VisualStateGroup>
  47:                              </VisualStateManager.VisualStateGroups>
  48:                              <Image Source="/Weather;component/UserControl/base.png" Stretch="Fill"/>
  49:                              <Image Margin="90,-14,0,32" Source="{Binding cityWeatherIcon}"/>
  50:                              <TextBlock Text="{Binding cityTemperature}" FontSize="20"  Width="100" Margin="8,8,8,8" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/>
  51:                              <ContentPresenter HorizontalAlignment="Left" Height="40" Margin="8,8,0,0" VerticalAlignment="Top"/>
  52:                          </Grid>
  53:                      </ControlTemplate>
  54:                  </Setter.Value>
  55:              </Setter>
  56:              <Setter Property="FontSize" Value="26"/>
  57:              <Setter Property="Foreground" Value="White"/>
  58:          </Style>
  59:      </UserControl.Resources>
  60:      <Button Name="cityName" Content="{Binding cityName}" Style="{StaticResource ButtonStyle1}"/>
  61:  </UserControl>

因為城市列表的控件個數是由獨立存儲中的數據動態加載的,賦值代碼如下。

   1:  private void AddCity(string cityName, string cityTemperature, string WeatherIconPath) 
   2:          {
   3:              CityTileData cityData = new CityTileData();
   4:              cityData.cityTemperature = cityTemperature;
   5:              cityData.cityWeatherIcon = WeatherIconPath;
   6:              CityTile city = new CityTile();
   7:              city.DataContext = cityData;
   8:              city.cityName.Content = cityName;
   9:              city.Width = 184;
  10:              city.Height = 105;
  11:              city.Margin = new Thickness(15, 10, 15, 10);
  12:              wrapPanelCityList.Children.Add(city);
  13:              city.cityName.Click += new RoutedEventHandler(cityName_Click);
  14:          }
  15:   
  16:          void cityName_Click(object sender, RoutedEventArgs e)
  17:          {
  18:              NavigationService.Navigate(new Uri("/Loading.xaml?cityName=" + ((Button)sender).Content + "&AndGoPage=WeatherView", UriKind.RelativeOrAbsolute));
  19:          }

再過20天考試完了,就畢業了。現在找個工作是真難,沒有工作經驗的應屆畢業生沒人要啊。做手機開發那么長時間了,連智能手機都買不起。諾基亞168C一直跟着我3年了。真是悲劇啊……求工作。感覺現在公司都很注重工作經驗,技術再強也不如有工作經驗。我想說的是應屆畢業生里也是有能力的,工作好幾年的也有能力不強的。

作者QQ:29992379


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM