C# 弹出控件不随窗口移动,而在调整窗口大小后移动窗口
我面临WPF弹出控件的一个问题。C# 弹出控件不随窗口移动,而在调整窗口大小后移动窗口,c#,wpf,popup,wpf-controls,wpf-positioning,C#,Wpf,Popup,Wpf Controls,Wpf Positioning,我面临WPF弹出控件的一个问题。 当我们调整窗口大小并移动它时,弹出控件保持在先前打开的位置,不会随窗口一起移动 那么这个问题的解决方案是什么呢。 请提供解决方案的代码段(如果有)。谢谢:) 弹出控件的Xaml代码如下所示: <Popup x:Name="popNonTopMostPopup" Height="200" Width="220" AllowsTransparency="True" Placement="Right"> <Grid Backg
当我们调整窗口大小并移动它时,弹出控件保持在先前打开的位置,不会随窗口一起移动
那么这个问题的解决方案是什么呢。 请提供解决方案的代码段(如果有)。谢谢:) 弹出控件的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>
提供代码阅读这个问题我用代码片段@PeterI更新了这个问题。我不认为有一个超级简单的解决方案。但是这里有一个运行得非常好的框架——我也在我当前的项目中使用它。它提供了您可能想要的功能:)。它可以在nuget商店中使用-非常方便。而且它是开源的-为什么不看看他们是如何做到的?提供代码请阅读此我用代码片段更新了问题@PeterI不认为有一个超级简单的解决方案。但是这里有一个运行得非常好的框架——我也在我当前的项目中使用它。它提供了您可能想要的功能:)。它可以在nuget商店中使用-非常方便。而且它是开源的-为什么不看看他们是如何做到的呢?
void pin_MouseLeftButtonDownForOrder(object sender, MouseButtonEventArgs e)
{
// set the placement target of popup as pin mapicon
popNonTopMostPopup.PlacementTarget = orderIcon;
popNonTopMostPopup.IsOpen = true;
}