windows Phone 7,按钮模板图像源绑定
我在每个 PivotItem 中都有带有 ListBoxes 的 Pivot。我已经制作了按钮控件来为列表框中的项目设置动画。这些按钮有一棵树 - 每个按钮都有不同的图像。然而,也许有某种方法可以制作一个按钮并仅绑定图像源。我认为这会改善加载页面时间。
我将感谢任何答复。
这是我的代码:
<DataTemplate x:Key="pageItemTemplate">
<Button Content="{Binding name}" Margin="0,0,0,20" Style="{StaticResource PageListItemButton}"/>
</DataTemplate>
<Style x:Key="PageListItemButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<StackPanel x:Name="stackPanel" Orientation="Horizontal">
<StackPanel.Projection>
<PlaneProjection CenterOfRotationY="0" CenterOfRotationX="1"/>
</StackPanel.Projection>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.05">
<VisualTransition.GeneratedEasingFunction>
<CircleEase EasingMode="EaseInOut"/>
</VisualTransition.GeneratedEasingFunction>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation Duration="0" To="15" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="stackPanel" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="0.7" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="stackPanel" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image Source="Images/MainPage/page.png" Height="40" Stretch="Fill" Width="40"/>
<ContentPresenter VerticalAlignment="Bottom"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FontFamily" Value="/BestNote;component/Fonts/Fonts.zip#Diavlo Bold"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="24"/>
<Setter Property="Foreground" Value="#FF292929"/>
</Style>
I have got Pivot with ListBoxes in each PevotItem. I've made Button control for animating items in ListBoxes. There is tree of those buttons - each of them has different image in it. However maybe there is some way to make one Button and just bind the image source. I think it will improve loading page time.
I will be thankful for any answer.
Here is my code:
<DataTemplate x:Key="pageItemTemplate">
<Button Content="{Binding name}" Margin="0,0,0,20" Style="{StaticResource PageListItemButton}"/>
</DataTemplate>
<Style x:Key="PageListItemButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<StackPanel x:Name="stackPanel" Orientation="Horizontal">
<StackPanel.Projection>
<PlaneProjection CenterOfRotationY="0" CenterOfRotationX="1"/>
</StackPanel.Projection>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.05">
<VisualTransition.GeneratedEasingFunction>
<CircleEase EasingMode="EaseInOut"/>
</VisualTransition.GeneratedEasingFunction>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation Duration="0" To="15" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="stackPanel" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="0.7" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="stackPanel" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image Source="Images/MainPage/page.png" Height="40" Stretch="Fill" Width="40"/>
<ContentPresenter VerticalAlignment="Bottom"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FontFamily" Value="/BestNote;component/Fonts/Fonts.zip#Diavlo Bold"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="24"/>
<Setter Property="Foreground" Value="#FF292929"/>
</Style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您发现一张图像(大小适合按钮)的加载时间足以导致打开页面的延迟,也许可以将该图像的大小减小到更适合该大小的图像。
或者,也许可以进行一些分析来确定实际花费时间加载此页面的内容......它可能不是花费大部分时间的图像。
您可以使用调试输出和 TimeSpans 进行简单的分析,或者尝试使用 EQATEC 分析器之类的工具。
If you're finding the loading time of one image (sized for a button) is substantial enough to cause a delay opening the page, perhaps the image can be reduced in size to something more suitable for an image of that size.
Alternatively, perhaps do some profiling to identify what is actualy taking the time to load this page .. it may not be the image taking the majority of the time.
You could do simple profiling with debug output and TimeSpans, or try something like the EQATEC profiler.