C# WPF将内容扩展到窗口外部
我想在wpf中获得以下效果 主窗口如下所示 当你点击好友面板时,好友列表应该扩展到窗口之外 当我点击那个列表中的项目时,我必须能够捕捉那个事件并在主窗口中处理它 如何在wpf中实现这一点 我曾尝试使用expander,但它不会显示不适合窗口大小的内容。它只是显示部分内容您可以使用弹出控件,并根据单击的按钮设置其位置目标和位置。简单的例子:C# WPF将内容扩展到窗口外部,c#,.net,wpf,C#,.net,Wpf,我想在wpf中获得以下效果 主窗口如下所示 当你点击好友面板时,好友列表应该扩展到窗口之外 当我点击那个列表中的项目时,我必须能够捕捉那个事件并在主窗口中处理它 如何在wpf中实现这一点 我曾尝试使用expander,但它不会显示不适合窗口大小的内容。它只是显示部分内容您可以使用弹出控件,并根据单击的按钮设置其位置目标和位置。简单的例子: <Grid> <Grid.RowDefinitions> <RowDefinition><
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Popup StaysOpen="False" Width="300" Height="200" x:Name="MyPopup">
<Popup.Child>
<StackPanel Background="Bisque"></StackPanel>
</Popup.Child>
</Popup>
<Button Margin="25,25,0,25" HorizontalAlignment="Right" Width="100" Click="ButtonBase_OnClick">First</Button>
<Button Grid.Row="1" Margin="25,25,0,25" HorizontalAlignment="Right" Width="100" Click="ButtonBase_OnClick">Second</Button>
<Button Grid.Row="2" Margin="25,25,0,25" HorizontalAlignment="Right" Width="100" Click="ButtonBase_OnClick">Third</Button>
</Grid>
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
MyPopup.IsOpen = false;
MyPopup.PlacementTarget = sender as UIElement;
MyPopup.Placement = PlacementMode.Right;
MyPopup.AllowsTransparency = true;
MyPopup.PopupAnimation = PopupAnimation.Fade;
MyPopup.IsOpen = true;
}
您可以使用弹出控件并根据单击的按钮设置其位置目标和位置。简单的例子:
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Popup StaysOpen="False" Width="300" Height="200" x:Name="MyPopup">
<Popup.Child>
<StackPanel Background="Bisque"></StackPanel>
</Popup.Child>
</Popup>
<Button Margin="25,25,0,25" HorizontalAlignment="Right" Width="100" Click="ButtonBase_OnClick">First</Button>
<Button Grid.Row="1" Margin="25,25,0,25" HorizontalAlignment="Right" Width="100" Click="ButtonBase_OnClick">Second</Button>
<Button Grid.Row="2" Margin="25,25,0,25" HorizontalAlignment="Right" Width="100" Click="ButtonBase_OnClick">Third</Button>
</Grid>
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
MyPopup.IsOpen = false;
MyPopup.PlacementTarget = sender as UIElement;
MyPopup.Placement = PlacementMode.Right;
MyPopup.AllowsTransparency = true;
MyPopup.PopupAnimation = PopupAnimation.Fade;
MyPopup.IsOpen = true;
}
您可以在自定义窗口样式上使用正确的设置进行类似的操作您可以在自定义窗口样式上使用正确的设置进行类似的操作