我需要在 XAML 弹出窗口的右上角放置一个标签

本文关键字:标签 一个 右上角 XAML 窗口 | 更新日期: 2023-09-27 18:35:19

这是我的代码。我已经尝试了几种方法来将标签放在弹出窗口的右上角并使其保留在那里,但没有任何效果。感谢您的帮助!

XAML:

<Window x:Class="ValidationWPF.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                xmlns:local="clr-namespace:ValidationWPF"
                Title="MainWindow" mc:Ignorable="d" 
                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="259" d:DesignWidth="420" SizeToContent="WidthAndHeight">
    <Grid Height="129" Width="345">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="514*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="0" />
            <RowDefinition Height="251*" />
        </Grid.RowDefinitions>
        <Button Content="Errors" Height="23" HorizontalAlignment="Left" Name="button1" VerticalAlignment="Top" Width="75" Grid.Column="1" Grid.Row="1" Margin="132,12,0,0" MouseEnter="button1_MouseHover">
        </Button>


            <Popup AllowsTransparency="True" PlacementTarget="{Binding ElementName=button1}" StaysOpen="True" AllowDrop="True" Name="PopUp1" PopupAnimation="Scroll">
            <Popup.Child>
          <Border BorderBrush="White" BorderThickness="3, 3, 0, 0">
            <Border BorderBrush="Black" BorderThickness="3, 3, 3, 3">
                <TextBlock Background="Salmon">
                  <Label Background="AliceBlue" Foreground="Black" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" MouseDown="mouse_DownHandeled" AllowDrop="False" Margin="100,100,0,0">
                    x
                    </Label>
                    <local:ValidationUserControl/>
                </TextBlock>      
            </Border>
        </Border>
         </Popup.Child>
            </Popup>
     </Grid>
</Window>

如您所见,我有一个弹出窗口,其中包含一个带有 X 的标签。标签功能齐全。现在我只需要它看起来像一个普通的弹出窗口,右上角有标签。

我需要在 XAML 弹出窗口的右上角放置一个标签

试试这个:

<TextBlock Background="Salmon" MinWidth="150" MinHeight="150" VerticalAlignment="Top">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120" />
            <ColumnDefinition Width="30" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="120" />
        </Grid.RowDefinitions>
        <Label Grid.Row="0" Grid.Column="1" Background="AliceBlue" Foreground="Black" VerticalAlignment="Top" AllowDrop="False">
            X
        </Label>
    </Grid>                                
</TextBlock>