1

我面临一个 WPF 弹出控件问题。
当我们调整窗口大小并移动它时,PopUp 控件保持在它之前打开的位置,并且不随窗口移动
那么这个问题的解决方案是什么。请提供解决方案的代码片段(如果有)。谢谢 :)

弹出控件的Xaml代码如下:

<Popup x:Name="popNonTopMostPopup" Height="200" Width="220" AllowsTransparency="True" Placement="Right">
            <Grid Background="Transparent">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <fa:FontAwesome Grid.Column="0" Icon="Play" FontSize="30" HorizontalAlignment="Right" Rotation="180" VerticalAlignment="Top" Margin="0 7 -2 0" />
                <Border Grid.Column="1" BorderBrush="LightGray" Background="Black" CornerRadius="5" Height="200" Width="200">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Button x:Name="btnCustomPopup" Click="btnCustomPopup_Click" HorizontalAlignment="Right" Background="Transparent" Foreground="LightGray" BorderBrush="Transparent" Grid.Row="0">
                            <StackPanel Margin="0">
                                <fa:FontAwesome Icon="Close" VerticalAlignment="Center" />
                            </StackPanel>
                        </Button>
                        <Label x:Name="lblName" Grid.Row="1" Foreground="LightGray"/>
                        <Grid Grid.Row="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Label x:Name="lblDueDate" Foreground="LightGray" Content="Fristdatum: " Grid.Column="0" VerticalAlignment="Bottom" Visibility="Hidden"></Label>
                            <TextBlock x:Name="txtDueDate" Foreground="LightGray" HorizontalAlignment="Left" Grid.Column="1" VerticalAlignment="Center" Visibility="Hidden"></TextBlock>
                        </Grid>
                        <Separator Grid.Row="3"></Separator>
                        <TextBlock x:Name="txtComments" Foreground="LightGray" TextWrapping="WrapWithOverflow" Grid.Row="4" Margin="10 10 10 10"></TextBlock>
                    </Grid>
                </Border>
            </Grid>
        </Popup>

我们在地图上点击显示弹出控件的图标。点击事件的代码如下。

void pin_MouseLeftButtonDownForOrder(object sender, MouseButtonEventArgs e)
{
      // set the placement target of popup as pin mapicon
      popNonTopMostPopup.PlacementTarget = orderIcon;
      popNonTopMostPopup.IsOpen = true;
}
4

0 回答 0