【问题标题】:How to render Window custom Title using XAML?如何使用 XAML 呈现窗口自定义标题?
【发布时间】:2015-10-29 12:44:30
【问题描述】:

我有一个 Windows 窗体应用程序,它在大多数应用程序窗体上显示应用程序名称,如下所示。对于应用程序名称“VScodePrint 2015”,我使用了位图。为了支持高分辨率屏幕,我必须制作该图像的多个副本以支持不同的 DPI 设置。

我刚刚开始使用 WPF 重新设计我的应用程序,以避免在不使用图像的情况下根据 DPI 设置设置不同的图像。

我创建了一个 WPF 窗口,但不确定如何呈现应用程序名称,如上面的 Windows 窗体版本。

能否请教我如何使用 XAML 按照 Windows 窗体版本呈现应用程序?

【问题讨论】:

    标签: wpf


    【解决方案1】:
    System.IO.Path.GetFileName(Assembly.GetEntryAssembly().GetName().Name);
    

    设置一个标签或任何与之相同的控件内容,您将获得所需的名称。

    【讨论】:

    • 只要我想要名称但我希望文本“2015”与名称的 RHS 对齐,如图所示
    • 好的,所以在显示应用程序名称的标签上方制作一个标签。然后在顶部标签的 XAML 中,放置 Horizo​​ntalContentAlignment="Right" ,这将使其与右侧对齐标签。
    【解决方案2】:

    我已经设法创建了一个用户控件,它为我的窗口呈现窗口标题。我是使用 WPF 的新手,所以这可能不是最好的 XAML,但它是:

    <UserControl x:Class="WindowTitle"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfApplication2"
             mc:Ignorable="d" Height="109.986" Width="404.929">
    

      <RowDefinition Height="80"/>
    
      <RowDefinition/>
    
    </Grid.RowDefinitions>
    <Border BorderBrush="DarkGray" BorderThickness="1" CornerRadius="10,10,0,0 " Background="#FF61238B" Margin="0,0,0,1">
      <StackPanel Width="Auto" Height="Auto">
        <StackPanel Height="Auto" Margin="0,0,0,0" HorizontalAlignment="Center" >
          <Label x:Name="lblYear" Content="2015" FontSize="12" BorderBrush="White" Foreground="White" HorizontalContentAlignment="Right" Padding="0,0,0,0" VerticalAlignment="Bottom" FontFamily="Global User Interface" Margin="0,5,0,0"/>
          <Label x:Name="lblProductName" Content="VScodePrint" FontSize="48" BorderBrush="White" Foreground="White" HorizontalContentAlignment="Right" Padding="0,0,0,0" VerticalAlignment="Top" FontFamily="Global User Interface" Margin="0,-5,0,0"/>
        </StackPanel>
    
      </StackPanel>
    </Border>
    <Label x:Name="lblVersion" Content="Version 14.0.20 Rev 1510" Grid.Row="1" VerticalAlignment="Center"  Height="37" HorizontalContentAlignment="Center"  Margin="0,0,0.429,0" FontFamily="Segoe UI Semibold">
      <Label.Background>
        <SolidColorBrush Color="#FFDBCBE3"/>
      </Label.Background>
    </Label>
    

    【讨论】:

      【解决方案3】:

      下面是上面的窗口标题用户控件的操作:

      【讨论】:

        猜你喜欢
        • 2014-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-25
        • 1970-01-01
        • 2022-11-04
        • 2016-06-10
        • 2010-09-11
        相关资源
        最近更新 更多