簡體   English   中英

C#WPF應用程序UI在其他計算機上真的很慢

[英]c# WPF application UI really slow on other computers

我不知道這聽起來有多模糊,所以如果您需要更多信息,請告訴我!

我已經完成程序,並且嘗試在其他計算機上運行該程序,但尚未使用任何安裝程序進行部署,只是在編譯后使用了debug / release programName.exe。

我的問題是,當程序不在編譯時所在的系統上運行時,為什么我的程序運行異常緩慢是有原因的嗎? 整個用戶界面滯后,因為它需要幾個部分才能切換到另一個選項卡,而在其本機計算機上運行時,它運行得非常流暢。

我已經嘗試過發布向導,所以我認為這不會有所幫助。 我想知道是否與我的xaml,DLL或程序的依賴項有關? 目前,我沒有任何圖片或資源。

我將為使此操作更平穩地進行任何更改提供任何建議,將不勝感激。

這是我的mainWindow Xaml:

       <Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:custom="clr-namespace:RemotePatch"
    x:Class="RemotePatch.MainWindow"
    mc:Ignorable="d"
    Title="Remote Patch" Height="350" Width="525" AllowsTransparency="True" WindowStyle="None" ResizeMode="CanResizeWithGrip" Loaded="Window_Loaded_1" Closed="Window_Closed">

<Window.Effect>
    <DropShadowEffect BlurRadius="0" ShadowDepth="0" Direction="0" Opacity="0"/>
</Window.Effect>
<Grid RenderTransformOrigin="0.497,0.518">

    <Grid.RowDefinitions>
        <RowDefinition Height="32" />
        <RowDefinition/>
        <RowDefinition Height="317*"/>

    </Grid.RowDefinitions>


    <Grid.Background>
        <RadialGradientBrush Center="0.5,0.6">
            <GradientStop Color="#FF1A8BA2"/>
            <GradientStop Color="#FF293855" Offset="1"/>
            <GradientStop Color="#FF1799AE" Offset="0.043"/>
        </RadialGradientBrush>
    </Grid.Background>
    <Rectangle Fill="#FFF4F4F5" Height="29" Stroke="Black" VerticalAlignment="Top" Opacity="0" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown"/>
    <TabControl x:Name="tabControl" Margin="0,5,0,16" Grid.Row="2" >
        <TabControl.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabItem}">
                            <Border x:Name="Border" BorderThickness="1,1,1,0" BorderBrush="Gainsboro" CornerRadius="4,4,4,4" Margin="2,0">
                                <ContentPresenter x:Name="ContentSite"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Center"
                                    ContentSource="Header"
                                    Margin="10,2"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter TargetName="Border" Property="Background" Value="LightSkyBlue" />
                                </Trigger>
                                <Trigger Property="IsSelected" Value="False">
                                    <Setter TargetName="Border" Property="Background" Value="White" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </TabControl.Resources>
        <TabControl.Foreground>
            <ImageBrush/>
        </TabControl.Foreground>

        <TabControl.BorderBrush>
            <ImageBrush/>
        </TabControl.BorderBrush>
        <TabControl.Background>
            <ImageBrush/>
        </TabControl.Background>
        <TabItem Header="General" Margin="0,7,0,-7">
            <TabItem.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FF040101" Offset="1"/>
                </LinearGradientBrush>
            </TabItem.Background>


            <Grid>
                <ListBox x:Name="listBox1" Margin="4,154,358,0" Foreground="White" Background="#FF14142E"/>
                <TextBox x:Name="txtFile" Height="18" Margin="79,80,264,0" TextWrapping="Wrap" VerticalAlignment="Top" Background="#FF14142E" Foreground="White" MinWidth="56"/>
                <TextBox x:Name="txtPSexec" Height="18" Margin="79,47,264,0" TextWrapping="Wrap" VerticalAlignment="Top" Background="#FF14142E" Foreground="White" MinWidth="56" />
                <TextBox x:Name="txtGroups" HorizontalAlignment="Left" Height="18" Margin="79,119,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="65" Background="#FF14142E" Foreground="White"/>
                <Button x:Name="buttonLoad" Content="Load File" Margin="4,78,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="56" Click="Load_Clicked">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0.27"/>
                            <GradientStop Color="#FF4F4F4F" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Button x:Name="buttonSplit" Content="Split" Margin="4,117,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="56" Click="Split_Clicked">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0.27"/>
                            <GradientStop Color="#FF4F4F4F" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Button x:Name="buttonValidate" Content="✔" Foreground="White" Height="15" VerticalAlignment="Top" HorizontalAlignment="Right" Width="15" Click="Validate_Clicked" FontSize="10.667" RenderTransformOrigin="0.062,0" Margin="0,154,358,0" FontWeight="Bold" >
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0.413"/>
                            <GradientStop Color="#FF6C6C6C" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Button x:Name="buttonPsExec" Content="PsExec" Margin="4,46,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="58" Click="Psexec_Click">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0.27"/>
                            <GradientStop Color="#FF4F4F4F" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Button x:Name="buttonLoginMain" Content="Login" Margin="452,6,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="58" Click="Login_Clicked">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0.27"/>
                            <GradientStop Color="#FF4F4F4F" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
            </Grid>


        </TabItem>

        <TabItem Header="Log" Margin="-3,7,3,-7">
            <Grid>
                <Grid.Background>
                    <ImageBrush/>
                </Grid.Background>
                <RichTextBox x:Name="richTextBox1" Margin="0,6,0,5" Background="Black" Foreground="White" TextChanged="richTextBox1_TextChanged" IsReadOnly="True">
                    <FlowDocument>
                        <Paragraph>
                            <Run Text="Remote Patch v2.0"/>
                        </Paragraph>
                    </FlowDocument>
                </RichTextBox>
            </Grid>
        </TabItem>
        <TabItem Header="Patch" Margin="-3,7,3,-7">
            <Grid Margin="0,5,0.333,-5.333">
                <Grid.Background>
                    <ImageBrush/>
                </Grid.Background>

                <Button x:Name="buttonLogin" Content="Login" Margin="0,10,1,0" Foreground="White" FontWeight="Bold" Grid.Row="2" Height="20" VerticalAlignment="Top" HorizontalAlignment="Right" Width="47" Click="Login_Clicked">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0.27"/>
                            <GradientStop Color="#FF4F4F4F" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <GroupBox x:Name="groupBox" Header="Predefined Patches&#xA;" Margin="27,56,87,0" VerticalAlignment="Top" Height="55" Foreground="White">
                    <Button x:Name="buttonPredefined" Content="Run" Margin="9,-7,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="51" Click="buttonPredefined_Click">
                        <Button.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="Black" Offset="0.27"/>
                                <GradientStop Color="#FF4F4F4F" Offset="1"/>
                            </LinearGradientBrush>
                        </Button.Background>
                    </Button>
                </GroupBox>
                <ComboBox x:Name="comboBox" Margin="132,81,102,0" VerticalAlignment="Top" Background="#FF0F0F59"  SelectionChanged="comboBox_SelectionChanged" Foreground="Black" />

                <GroupBox x:Name="groupBox_Copy" Header="Batch File&#xA;" Margin="27,143,82,0" VerticalAlignment="Top" Height="55" Foreground="White">
                    <Button x:Name="buttonBatch" Content="Run" Margin="0,40,0,-43" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="51" Click="Batch_Clicked" Visibility="Hidden">
                        <Button.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="Black" Offset="0.27"/>
                                <GradientStop Color="#FF4F4F4F" Offset="1"/>
                            </LinearGradientBrush>
                        </Button.Background>
                    </Button>
                </GroupBox>
                <TextBox x:Name="txtBatchFile" Height="23" Margin="127,168,102,0" TextWrapping="Wrap" VerticalAlignment="Top" Background="#FF14142E" Foreground="White"/>
                <Button x:Name="ButtonRunBatch" Content="Run" Margin="42,168,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="51" Click="loopBatch_Clicked">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0.27"/>
                            <GradientStop Color="#FF4F4F4F" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Button x:Name="buttonAddFile" Content="+" Margin="0,168,47,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" Click="Add_Clicked" HorizontalAlignment="Right" Width="30">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0.27"/>
                            <GradientStop Color="#FF4F4F4F" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Grid HorizontalAlignment="Left" Height="35" Margin="182,198,0,0" VerticalAlignment="Top" Width="106">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Height="40" Margin="25,5,-13,-10" VerticalAlignment="Top" Width="94">
                        <TextBox x:Name="numerical" TextWrapping="Wrap" Width="34" Margin="0,10,0,9.667" Background="#FF14142E" Foreground="White" TextChanged="textBox_TextChanged"/>
                        <Button x:Name="button1" Content="-" HorizontalAlignment="Left" VerticalAlignment="Top" Width="14" Height="19" Margin="0,10,0,0" Background="#FFFFEFEF" FontSize="10.667" FontWeight="Bold" Click="button1_Click"/>
                        <Button x:Name="button" Content="+" HorizontalAlignment="Left" VerticalAlignment="Top" Width="14" Height="19" Margin="0,10,0,0" FontSize="10.667" FontWeight="Bold" Click="addNumValue"/>
                    </StackPanel>
                </Grid>
                <Label x:Name="label2" Content="Groups" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="209,231,0,0" Foreground="White"/>

            </Grid>
        </TabItem>
    </TabControl>

    <Button x:Name="button2" Content="-" Margin="0,2,53,10" Foreground="White" FontWeight="Bold" HorizontalAlignment="Right" Width="21" Click="Minimize_Click">
        <Button.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0.27"/>
                <GradientStop Color="#FF4F4F4F" Offset="1"/>
            </LinearGradientBrush>
        </Button.Background>
    </Button>
    <Button x:Name="button2_Copy" Margin="0,2,27,10" Foreground="White" HorizontalAlignment="Right" Width="21" Click="Maximize_Click">
        <Button.Background>

            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0.27"/>
                <GradientStop Color="#FF4F4F4F" Offset="1"/>
            </LinearGradientBrush>
        </Button.Background>
        <Canvas>
            <Rectangle Height="9" Width="9"  Stroke="White" Canvas.Top="-2" Canvas.Left="-4"/>
            <Rectangle  Height="10" Width="10"  Stroke="White" Canvas.Left="-2" Canvas.Top="-7" RenderTransformOrigin="0.5,0.5">
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="-0.715"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Rectangle.RenderTransform>
            </Rectangle>
        </Canvas>
    </Button>
    <Button x:Name="button2_Copy1" Content="X" Margin="0,2,0,10" Foreground="White" FontWeight="Bold" HorizontalAlignment="Right" Width="22" Click="button2_Copy1_Click">

        <Button.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0.27"/>
                <GradientStop Color="#FF4F4F4F" Offset="1"/>
            </LinearGradientBrush>
        </Button.Background>
    </Button>
    <Label x:Name="label" Content="Remote Patch" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Width="108" Foreground="White" FontSize="16" IsHitTestVisible="False"/>


    <Rectangle Grid.Row="2" Height="20" VerticalAlignment="Bottom" Fill="Transparent" Margin="-1,0,0,0"/>
    <Label x:Name="label1" Content="Authenticated" HorizontalAlignment="Left" Grid.Row="2" Width="84" RenderTransformOrigin="0.5,0.5" Foreground="White" Height="23" VerticalAlignment="Bottom">
        <Label.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform AngleY="-0.718"/>
                <RotateTransform/>
                <TranslateTransform Y="-0.294"/>
            </TransformGroup>
        </Label.RenderTransform>
    </Label>
    <Ellipse x:Name="authColor" Fill="Red" HorizontalAlignment="Left" Margin="83,0,0,4" Grid.Row="2" Stroke="Black" Width="13" Height="13" VerticalAlignment="Bottom"/>
    <Label x:Name="labelSettings" Content="Settings" Margin="0,-1,84,0" VerticalAlignment="Top" Foreground="#FF595555" FontWeight="Bold" HorizontalAlignment="Right" Width="56" MouseLeftButtonDown="labelSettings_MouseLeftButtonDown"/>
    <Rectangle x:Name="rectangleNotification" Fill="#FFDDFF03" Grid.Row="2" Stroke="Black" Height="25" VerticalAlignment="Bottom" Opacity="0" Margin="0,0,1,0"/>
    <Rectangle Height="2" Margin="30,31,30,0" Stroke="#FF444444" VerticalAlignment="Top" Grid.RowSpan="2" Opacity="0.5"/>

</Grid>
</Window>

您已將DropShadowEffect應用於Window

這是一個問題,因為DropShadowEffect使用所有后代對象來計算陰影的形狀。 這意味着在渲染時,此效果將檢查Window中包含的每個對象-這確實需要很長時間。

陰影效果的不透明度為0,因此可以將其刪除。 或者,應將效果應用於“窗口”的子級,但要確​​保該子級沒有后代。

我在不影響性能的情況下將陰影應用於窗口的技巧是將窗口的內容圍繞在網格中,在該網格的頂部放置邊框(或類似對象)(切記為邊框分配背景)您將不會得到陰影),然后將效果應用於邊框而不是窗口。

之前:

<Window x:Class="MyProject.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="300" Width="400"
        WindowStyle="None" AllowsTransparency="True" Background="Transparent">

    <Window.Effect>
        <DropShadowEffect BlurRadius="10" ShadowDepth="0"/>
    </Window.Effect>

    <StackPanel Margin="8" Background="White">
        <Button Margin="4">Test</Button>
        <Button Margin="4">Test</Button>
        <Button Margin="4">Test</Button>
    </StackPanel>

</Window>

后:

<Window x:Class="MyProject.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Height="300" Width="400"
            WindowStyle="None" AllowsTransparency="True" Background="Transparent">

    <Grid Margin="8">
        <Border Background="White">
            <Border.Effect>
                <DropShadowEffect BlurRadius="10" ShadowDepth="0"/>
            </Border.Effect>
        </Border>
        <StackPanel>
            <Button Margin="4">Test</Button>
            <Button Margin="4">Test</Button>
            <Button Margin="4">Test</Button>
        </StackPanel>
    </Grid>

</Window>

這提供了完全相同的外觀,但是具有更好的性能,因為:

  • 按鈕不再參與陰影的計算
  • 邊框沒有后代,因此效果僅在計算中使用邊框的布局

一般經驗法則... 僅將投影效果應用於其祖先將要受到效果影響的對象

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM