在我们调整窗口大小后移动窗口时,PopUp控件不随窗口移动

时间:2017-06-23 08:52:14

标签: c# wpf popup wpf-controls wpf-positioning

我遇到了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;
}

0 个答案:

没有答案