为什么WPF XAML在运行时运行缓慢?

时间:2014-09-10 04:47:16

标签: .net wpf xaml wpf-controls powerbuilder.net

我使用powerbuilder.net 12.5和WPF创建了一个项目。

没有任何效果和动画。 Everthings跑得快而且好。直到我添加一些效果和动画时,它现在运行得非常慢,特别是在运行时。

我将如何解决这个问题?或者有没有办法压缩/优化我的代码?感谢。

这是我的xaml代码

<pbwpf:Window x:Class="w_main" x:ClassModifier="internal" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:pbwpf="clr-namespace:Sybase.PowerBuilder.WPF.Controls;assembly=Sybase.PowerBuilder.WPF.Controls" PBTitle="" PBHeight="2000" PBWidth="2500" MinBox="True" MaxBox="True" TitleBar="True" ControlMenu="True" Center="True" Resizable="True" Uid="21" Height="800" Width="1024" WindowStyle="None" AllowsTransparency="True" Background="Transparent" MenuName="m_menu" WindowType="Mdi" xmlns:my="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Grid SnapsToDevicePixels="True" Height="770" Width="1009" Background="Transparent">
    <Grid.Effect>
        <DropShadowEffect Color="Black" BlurRadius="15" Direction="100" ShadowDepth="1"/>
    </Grid.Effect>
    <Border Background="White" />
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="90" />
            <ColumnDefinition Width="680" />
            <ColumnDefinition Width="69" />
            <ColumnDefinition Width="170" />
        </Grid.ColumnDefinitions>
        <Border Grid.Row="1" Grid.Column="1">
            <pbwpf:MDIClient Visibility="Visible" Name="mdi_1" Margin="0" Background="#ffffff" Width="920"/>
        </Border>
        <Border UseLayoutRounding="True" Grid.Row="0" Grid.Column="2" Background="#2cb6d9" BorderBrush="#25a6c7" BorderThickness="1,0,1,1">
            <Grid>
                <Button Name="button_lgout">
                    <Button.Style>
                        <Style TargetType="Button">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type Button}">
                                        <ContentPresenter TextElement.Foreground="{TemplateBinding Foreground}" />
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Button.Style>
                    <StackPanel HorizontalAlignment="Center">
                        <Image Source="Images/logout.png" Height="21" HorizontalAlignment="Center" Margin="0,5,0,0" />
                        <Label Name="lbl_lgout" Content="LOGOUT" FontSize="12" Foreground="White" FontFamily="Calibri" HorizontalAlignment="Center" />
                    </StackPanel>
                </Button>
            </Grid>
        </Border>
        <Border Grid.Row="0" Grid.Column="3" Background="#2cb6d9" BorderBrush="#25a6c7" BorderThickness="0,0,0,1">
            <Grid VerticalAlignment="Center">
                <Image Source="Images/ics.png" UseLayoutRounding="True" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,-10,0" Height="90" />
                <Label Name="lbl_usr" Content="HELLO , I S G ! " FontFamily="Calibri" FontSize="13" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,52,0" Width="98"></Label>
            </Grid>
        </Border>
        <Border Grid.Row="0" Grid.Column="1" Background="#2cb6d9" BorderBrush="#25a6c7" BorderThickness="0,0,0,1"/>
        <Border Grid.Row="1" Grid.Column="0" Background="#dedede" BorderBrush="#d9dcdf" BorderThickness="0,0,1,0">
            <StackPanel Orientation="Vertical" Height="750" Background="#111111">
                <StackPanel.Resources>
                    <Style TargetType="my:RibbonButton" >
                        <Style.Resources>
                            <sys:Double x:Key="buttonSize">60</sys:Double>
                            <CornerRadius x:Key="buttonRadius">30</CornerRadius>
                            <sys:Double x:Key="scaleOffset">30</sys:Double>
                        </Style.Resources>
                        <Setter Property="Margin" Value="0,10,0,0" />
                        <Setter Property="Foreground" Value="White" />
                        <Setter Property="FontSize" Value="20" />
                        <Setter Property="FontWeight" Value="SemiBold" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="my:RibbonButton">
                                    <Border Background="Transparent" Width="{StaticResource buttonSize}" Height="{StaticResource buttonSize}" CornerRadius="{StaticResource buttonRadius}">
                                        <Grid>
                                            <Border Background="#22ffffff" CornerRadius="{StaticResource buttonRadius}" x:Name="content">
                                                <Image Height="27" x:Name="image" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" Source="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"></Image>
                                            </Border>
                                            <Ellipse x:Name="ring" StrokeThickness="15" Opacity="0" IsHitTestVisible="False">
                                                <Ellipse.Stroke>
                                                    <RadialGradientBrush>
                                                        <GradientStop Color="Transparent" Offset="0.83" />
                                                        <GradientStop Color="LightGray" Offset="0.84" />
                                                        <GradientStop Color="Transparent" Offset="0.85" />
                                                        <GradientStop Color="Transparent" Offset=".93" />
                                                        <GradientStop Color="#55ffffff" Offset=".97" />
                                                        <GradientStop Color="#55ffffff" Offset="1" />
                                                    </RadialGradientBrush>
                                                </Ellipse.Stroke>
                                                <Ellipse.RenderTransform>
                                                    <ScaleTransform CenterX="{StaticResource scaleOffset}" CenterY="{StaticResource scaleOffset}" x:Name="ringScale" />
                                                </Ellipse.RenderTransform>
                                            </Ellipse>
                                        </Grid>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="true">
                                            <Setter Property="Opacity" Value="0.2" />
                                            <Setter TargetName="content" Property="RenderTransform">
                                                <Setter.Value>
                                                    <ScaleTransform CenterX="{StaticResource scaleOffset}" CenterY="{StaticResource scaleOffset}" ScaleX=".9" ScaleY=".9" />
                                                </Setter.Value>
                                            </Setter>
                                            <Setter TargetName="image" Property="Source" Value="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                                            <Setter Property="Opacity" Value="1" />
                                            <Trigger.EnterActions>
                                                <BeginStoryboard>
                                                    <Storyboard Duration="0:0:2">
                                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ring" To="1" Duration="0:0:0" />
                                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ring" From="1" To="0" />
                                                        <DoubleAnimation Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="ringScale" From="1" To="1.5" />
                                                        <DoubleAnimation Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="ringScale" From="1" To="1.5" />
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </Trigger.EnterActions>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </StackPanel.Resources>
                <my:RibbonButton Name="rb_new" Margin="0,10,0,0" Content="Images/new_light.png" />
                <my:RibbonButton Name="rb_edit" Margin="0,10,0,0" Content="Images/edit_light.png" />
                <my:RibbonButton Name="rb_save" Margin="0,10,0,0" Content="Images/save_light.png" />
                <my:RibbonButton Name="rb_abort" Margin="0,10,0,0" Content="Images/cancel_light.png" />
                <my:RibbonButton Name="rb_trash" Margin="0,10,0,0" Content="Images/delete_light.png" />
                <my:RibbonButton Name="rb_search" Margin="0,10,0,0" Content="Images/search_light.png" />
                <my:RibbonButton Name="rb_print" Margin="0,10,0,0" Content="Images/print_light.png" />
            </StackPanel>
        </Border>
    </Grid>
</Grid>

1 个答案:

答案 0 :(得分:2)

根据我个人的经验,开发XAML是必要的,因为pc最好配备专用的视频卡。 然而,很多时候即使在非常老的电脑上使用Windows XP来瘦身程序我也安装了更新直接X库

http://support.microsoft.com/kb/179113/en

XAML基于directX