windows Phone 7,按钮模板图像源绑定

发布于 2024-10-07 08:39:45 字数 3179 浏览 4 评论 0原文

我在每个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗藏城府 2024-10-14 08:39:45

如果您发现一张图像(大小适合按钮)的加载时间足以导致打开页面的延迟,也许可以将该图像的大小减小到更适合该大小的图像。

或者,也许可以进行一些分析来确定实际花费时间加载此页面的内容......它可能不是花费大部分时间的图像。

您可以使用调试输出和 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文