WPF将内容扩展到窗口外

时间:2014-11-12 02:44:54

标签: c# .net wpf

我希望在wpf中获得以下效果

主窗口如下所示 Main window 当你点击朋友面板时,朋友列表应该扩展到窗外 Friends expanded

当我点击该列表中的项目时,我必须能够捕获该事件并在主窗口上处理 如何在wpf中实现呢?

我尝试过使用扩展程序,但它没有显示不符合窗口大小的内容。它只展示了内容的一部分

1 个答案:

答案 0 :(得分:5)

您可以使用Popup控件并根据单击的按钮设置其PlacementTargetPlacement。简单的例子:

<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;
    }