C# 如何在WPF中创建一个类似于;UWP“;应用程序?

C# 如何在WPF中创建一个类似于;UWP“;应用程序?,c#,wpf,uwp,windows-10,C#,Wpf,Uwp,Windows 10,我需要创建一个WPF自定义窗口,该窗口类似于: 我有办法做到吗 我试着使用MahApps.Metro窗口,但在调整大小时,窗口非常闪烁。 以下是示例代码: <Controls:MetroWindow x:Class="MahAppsMetroSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

我需要创建一个WPF自定义窗口,该窗口类似于:

我有办法做到吗

我试着使用MahApps.Metro窗口,但在调整大小时,窗口非常闪烁。 以下是示例代码:

 <Controls:MetroWindow x:Class="MahAppsMetroSample.MainWindow"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
                      xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
                      Title="MahApps.Metro.Sample"
                      GlowBrush="{DynamicResource AccentColorBrush}"
                      WindowStartupLocation="CenterScreen">

  <Controls:MetroWindow.RightWindowCommands>
    <Controls:WindowCommands>
      <Button Content="settings" />
      <Button>
        <StackPanel Orientation="Horizontal">
          <iconPacks:PackIconModern Width="24" Height="24" Kind="FoodCupcake" />
            <TextBlock Margin="4 0 0 0" VerticalAlignment="Center" Text="deploy cupcakes" />
        </StackPanel>
      </Button>
    </Controls:WindowCommands>
  </Controls:MetroWindow.RightWindowCommands>

  <Grid>
  </Grid>

</Controls:MetroWindow>

是的,您可以使用一个名为UWP主机的包来实现它。



第一步:

您所需要做的就是通过nuget将UWP主机导入到您的项目中。

步骤2:

将此代码添加到App.xaml文件中

<Application.Resources>
  <ResourceDictionary>
       <ResourceDictionary.MergedDictionaries>
           <ResourceDictionary Source="pack://application:,,,/UWPHost;component/Themes/Generic.xaml" />
       </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>

步骤4:

将uwp前缀添加到窗口标记中,并确保其外观与此类似


就是这样

我以前使用过mahapps.metro,但是当我调整窗口大小时,窗口非常闪烁谢谢你,它工作正常
xmlns:uwp="clr-namespace:UWPHost;assembly=UWPHost"
<upw:Window x:Class="WpfApp1.MainWindow"
        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:local="clr-namespace:WpfApp1"
        xmlns:uwp="clr-namespace:UWPHost;assembly=UWPHost"
        mc:Ignorable="d"
        ShowTitlebar="true" Theme="Light"
        Title="MainWindow" Height="300" Width="300">

</uwp:Window>
public partial class MainWindow : UWPHost.Window{
   public MainWindow()
   {
       InitializeComponent();
   }
}