wp7 中 HubTile控件自定义大小。
http://blog.csdn.net/matrixcl/article/details/7057291 (转)
Toolkit(http://silverlight.codeplex.com/)中有一个不错的控件:HubTile。
但这个控件只能用于173*173的Tile,如果想放其他尺寸的的就麻烦一些了(一行并排3个显示的Tile)
下面是实现可重定义tile大小的完整代码
步骤1:写一个Converner类,用于缩放double类型的数值
需要命名空间:
using System.Globalization;
using System.Windows.Data;
- <span style="font-size:18px;"> public class DoubleScaleConverner : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value is double && targetType == typeof(double))
- {
- double dbOrig = (double)value;
- if (parameter is string)
- {
- double dbParam;
- if (double.TryParse((parameter as string), out dbParam))
- {
- return Math.Round(dbOrig * dbParam);
- }
- }
- }
- return value;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return null;
- }
- }</span>
2. ResourceDictionary文件中,将converner声明出来
- <span style="font-size:18px;">xmlns:my="clr-namespace:HubTileTest"
- an>
- <span style="font-size:18px;"> <my:DoubleScaleConverner x:Key="doubleScaleConverner" /></span>
3. 用blend生成hubtile的style,并做修改成这样
- <span style="font-size:18px;"><Style x:Key="customHubTileStyle" TargetType="toolkit:HubTile">
- <Style.Setters>
- <Setter Property="Height" Value="173"/>
- <Setter Property="Width" Value="173"/>
- <Setter Property="Background" Value="{StaticResource PhoneAccentBrush}"/>
- <Setter Property="Foreground" Value="#FFFFFFFF"/>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="toolkit:HubTile">
- <StackPanel x:Name="Viewport"
- Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
- <StackPanel.Resources>
- <CubicEase EasingMode="EaseOut" x:Key="HubTileEaseOut"/>
- </StackPanel.Resources>
- <StackPanel.Projection>
- <PlaneProjection CenterOfRotationY="0.25" x:Name="ViewportProjection"/>
- </StackPanel.Projection>
- <VisualStateManager.VisualStateGroups>
- <VisualStateGroup x:Name="ImageStates">
- <VisualStateGroup.Transitions>
- <VisualTransition x:Name="ExpandedToSemiexpanded"
- From="Expanded" To="Semiexpanded"
- GeneratedDuration="0:0:0.85">
- <Storyboard>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
- Storyboard.TargetName="TitlePanel">
- <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-1}" EasingFunction="{StaticResource HubTileEaseOut}"/>
- <EasingDoubleKeyFrame KeyTime="0:0:0.85" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-0.45665}" EasingFunction="{StaticResource HubTileEaseOut}"/>
- </DoubleAnimationUsingKeyFrames>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="RotationX"
- Storyboard.TargetName="ViewportProjection">
- <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="0.0" EasingFunction="{StaticResource HubTileEaseOut}"/>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- </VisualTransition>
- <VisualTransition x:Name="SemiexpandedToCollapsed"
- From="Semiexpanded" To="Collapsed"
- GeneratedDuration="0:0:0.85">
- <Storyboard>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
- Storyboard.TargetName="TitlePanel">
- <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-0.45665}" EasingFunction="{StaticResource HubTileEaseOut}"/>
- <EasingDoubleKeyFrame KeyTime="0:0:0.85" Value="0.0" EasingFunction="{StaticResource HubTileEaseOut}"/>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- </VisualTransition>
- <VisualTransition x:Name="CollapsedToExpanded"
- From="Collapsed" To="Expanded"
- GeneratedDuration="0:0:0.85">
- <Storyboard>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
- Storyboard.TargetName="TitlePanel">
- <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="0.0" EasingFunction="{StaticResource HubTileEaseOut}"/>
- <EasingDoubleKeyFrame KeyTime="0:0:0.85" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-1}" EasingFunction="{StaticResource HubTileEaseOut}"/>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- </VisualTransition>
- <VisualTransition x:Name="ExpandedToFlipped"
- From="Expanded" To="Flipped"
- GeneratedDuration="0:0:0.85">
- <Storyboard>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
- Storyboard.TargetName="TitlePanel">
- <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-1}" EasingFunction="{StaticResource HubTileEaseOut}"/>
- </DoubleAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
- Storyboard.TargetName="Image">
- <DiscreteObjectKeyFrame KeyTime="0:0:0.185" Value="Collapsed"/>
- </ObjectAnimationUsingKeyFrames>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="RotationX"
- Storyboard.TargetName="ViewportProjection">
- <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="0.0" EasingFunction="{StaticResource HubTileEaseOut}"/>
- <EasingDoubleKeyFrame KeyTime="0:0:0.85" Value="180.0" EasingFunction="{StaticResource HubTileEaseOut}"/>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- </VisualTransition>
- <VisualTransition x:Name="FlippedToExpanded"
- From="Flipped" To="Expanded"
- GeneratedDuration="0:0:0.85">
- <Storyboard>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
- Storyboard.TargetName="TitlePanel">
- <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-1}" EasingFunction="{StaticResource HubTileEaseOut}"/>
- </DoubleAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
- Storyboard.TargetName="Image">
- <DiscreteObjectKeyFrame KeyTime="0:0:0.185" Value="Visible"/>
- </ObjectAnimationUsingKeyFrames>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="RotationX"
- Storyboard.TargetName="ViewportProjection">
- <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="180.0" EasingFunction="{StaticResource HubTileEaseOut}"/>
- <EasingDoubleKeyFrame KeyTime="0:0:0.85" Value="360.0" EasingFunction="{StaticResource HubTileEaseOut}"/>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- </VisualTransition>
- </VisualStateGroup.Transitions>
- <VisualStateGroup.States>
- <VisualState x:Name="Expanded">
- <Storyboard>
- <DoubleAnimation Duration="0" To="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-1}"
- Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
- Storyboard.TargetName="TitlePanel"/>
- <DoubleAnimation Duration="0" To="0.0"
- Storyboard.TargetProperty="RotationX"
- Storyboard.TargetName="ViewportProjection"/>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
- Storyboard.TargetName="Image">
- <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="Semiexpanded">
- <Storyboard>
- <DoubleAnimation Duration="0" To="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-0.45665}"
- Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
- Storyboard.TargetName="TitlePanel"/>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="Collapsed"/>
- <VisualState x:Name="Flipped">
- <Storyboard>
- <DoubleAnimation Duration="0" To="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=-1}"
- Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
- Storyboard.TargetName="TitlePanel"/>
- <DoubleAnimation Duration="0" To="180.0"
- Storyboard.TargetProperty="RotationX"
- Storyboard.TargetName="ViewportProjection"/>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
- Storyboard.TargetName="Image">
- <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- </VisualStateGroup.States>
- </VisualStateGroup>
- </VisualStateManager.VisualStateGroups>
- <Grid x:Name="TitlePanel"
- Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=2}"
- Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height}"
- RenderTransformOrigin="0.5,0.5">
- <Grid.RenderTransform>
- <CompositeTransform/>
- </Grid.RenderTransform>
- <Grid.RowDefinitions>
- <RowDefinition/>
- <RowDefinition/>
- </Grid.RowDefinitions>
- <Border Grid.Row="0"
- Background="{TemplateBinding Background}">
- <TextBlock VerticalAlignment="Bottom"
- Margin="10,0,0,6"
- Text="{TemplateBinding Title}"
- FontFamily="{StaticResource PhoneFontFamilyNormal}"
- FontSize="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=0.22}"
- Foreground="{TemplateBinding Foreground}"
- TextWrapping="NoWrap"
- LineStackingStrategy="BlockLineHeight"
- LineHeight="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource doubleScaleConverner}, ConverterParameter=0.20}">
- </TextBlock>
- </Border>
- <Grid x:Name="BackPanel"
- Grid.Row="1"
- Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height}"
- Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height}"
- Background="{TemplateBinding Background}">
- <Grid.RowDefinitions>
- <RowDefinition Height="*"/>
- <RowDefinition Height="Auto"/>
- </Grid.RowDefinitions>
- <Grid.Projection>
- <PlaneProjection CenterOfRotationY="0.5" RotationX="180"/>
- </Grid.Projection>
- <TextBlock x:Name="NotificationBlock" Grid.Row="0"
- Margin="8,8,0,6"
- Text="{TemplateBinding Notification}"
- FontFamily="{StaticResource PhoneFontFamilyNormal}"
- FontSize="{StaticResource PhoneFontSizeLarge}"
- Foreground="{TemplateBinding Foreground}"
- TextWrapping="NoWrap"
- LineStackingStrategy="BlockLineHeight"
- LineHeight="32"/>
- <TextBlock x:Name="MessageBlock" Grid.Row="0"
- Margin="10,10,10,6"
- Text="{TemplateBinding Message}"
- FontFamily="{StaticResource PhoneFontFamilyNormal}"
- FontSize="{StaticResource PhoneFontSizeNormal}"
- Foreground="{TemplateBinding Foreground}"
- TextWrapping="Wrap"
- LineStackingStrategy="BlockLineHeight"
- LineHeight="23.333"/>
- <TextBlock x:Name="BackTitleBlock" Grid.Row="1"
- VerticalAlignment="Bottom"
- Margin="10,0,0,6"
- FontFamily="{StaticResource PhoneFontFamilySemiBold}"
- FontSize="{StaticResource PhoneFontSizeNormal}"
- Foreground="{TemplateBinding Foreground}"
- TextWrapping="NoWrap"/>
- </Grid>
- <Image x:Name="Image" Grid.Row="1"
- Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height}"
- Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height}"
- Stretch="UniformToFill"
- Source="{TemplateBinding Source}"/>
- </Grid>
- </StackPanel>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style.Setters>
- </Style></span>
4. 如果要使用一个136*136的tile,这样写个样式就行了
- <span style="font-size:18px;"> <Style x:Key="smallTileStyle" TargetType="toolkit:HubTile" BasedOn="{StaticResource customHubTileStyle}">
- <Setter Property="Height" Value="136" />
- <Setter Property="Width" Value="136" />
- <Setter Property="Background" Value="Purple" />
- </Style></span>

wp7 中 HubTile控件自定义大小。的更多相关文章
- MFC中改变控件的大小和位置
用CWnd类的函数MoveWindow()或SetWindowPos()可以改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...
- MFC中改变控件的大小和位置(zz)
用CWnd类的函数MoveWindow()或SetWindowPos()能够改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...
- onCreate中获得控件的大小
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setC ...
- C# Winform 界面中各控件随着窗口大小变化
在做一项工程中,由于不确定目标平台的分辨率,而正常使用要求铺满整个屏幕,所以界面中的各个控件必须能够适应窗口的变化. 首先想到的就是控件的百分比布局,但是再尝试写了几个控件的Location和Size ...
- 为Form中的控件增加自适应功能 转
创建一个基于Custom的类resizeable,并新建属性和方法程序,其说明如下: a) 新建属性: posiTyperList 可调整位置的控件类型列表sizeTypeList 可调整大小的控件类 ...
- MFC的停靠窗口中插入对话框,在对话框中添加控件并做控件自适应
单文档程序添加了停靠窗口后,可能会在停靠窗口中添加一些控件.在这里我的做法是在对话框上添加控件并布局,然后将这个对话框插入到停靠窗口中. 步骤 1.插入对话框,在对话框中放入控件(我的为树形控件),并 ...
- WinForm编程时窗体设计器中ComboBox控件大小的设置
问题描述: 在VS中的窗体设计器中拖放一个ComboBox控件后想调整控件的大小.发现在控件上用鼠标只能拖动宽度(Width)无法拖动(Height). 解决过程: 1.控件无法拖动,就在属性窗口中设 ...
- Android中动态改变控件的大小的一种方法
在Android中有时候我们需要动态改变控件的大小.有几种办法可以实现 一是在onMeasure中修改尺寸,二是在onLayout中修改位置和尺寸.这个是可以进行位置修改的,onMeasure不行. ...
- WPF中自定义的DataTemplate中的控件,在Window_Loaded事件中加载机制初探
原文:WPF中自定义的DataTemplate中的控件,在Window_Loaded事件中加载机制初探 最近因为项目需要,开始学习如何使用WPF开发桌面程序.使用WPF一段时间之后,感 ...
随机推荐
- 【GoLang】GoLang fmt 占位符详解
golang 的fmt 包实现了格式化I/O函数,类似于C的 printf 和 scanf. # 定义示例类型和变量 type Human struct { Name string } var peo ...
- 【SpringMVC】SpringMVC系列5之@RequestHeader 映射请求头属性值
5.@RequestHeader 映射请求头属性值 5.1.概述 请求头包含了若干个属性,服务器可据此获知客户端的信息,通过 @RequestHeader 即可将请求头中的属性值绑定到处理方法的入参中 ...
- sql SELECT时的with(nolock)选项说明
I used to see my senior developers use WITH (NOLOCK) when querying in SQL Server and wonder why they ...
- 字母排列_next_permutation_字典序函数_待解决
问题 B: 字母排列 时间限制: 1 Sec 内存限制: 64 MB提交: 19 解决: 5[提交][状态][讨论版] 题目描述 当给出一串字符时,我们逐个可以变换其字符,形成新的字符串.假如对这 ...
- ShortestPath:Layout(POJ 3169)(差分约束的应用)
布局 题目大意:有N头牛,编号1-N,按编号排成一排准备吃东西,有些牛的关系比较好,所以希望他们不超过一定的距离,也有一些牛的关系很不好,所以希望彼此之间要满足某个关系,牛可以 ...
- 如何从sun公司官网下载java API文档(转载)
相信很多同人和我一样,想去官网下载一份纯英文的java API文档,可使sun公司的网站让我实在很头疼,很乱,全是英文!所以就在网上下载了别人提供的下载!可是还是不甘心!其实多去看看这些英文的技术网站 ...
- SQLServer语句大使
1.创建数据库create database 数据库名字 2.删除数据库drop database 数据库名字3.创建表(identity(1,1)自动增长,倍数为1,primary key设置主键) ...
- Linux下创建ftp用户并锁定根目录
[root@d vsftpd]# vi /etc/vsftpd/chroot_list 加入要锁定根目录的ftp用户名(一行只能一个用户) [root@ vsftpd]# vi /etc/vsftpd ...
- Solr常用查询语法笔记
1.常用查询 q - 查询字符串,这个是必须的.如果查询所有*:* ,根据指定字段查询(Name:张三 AND Address:北京) fq - (filter query)过虑查询,作用:在q查询符 ...
- Java Hour 11
有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. 本文作者Java 现经验约为11 Hour,请各位不吝赐教. Hour 11 ...