日期:2014-05-17 浏览次数:20904 次
<Window x:Class="PopupTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<Grid x:Name="M" Background="Gray" MouseLeftButtonDown="M_MouseLeftButtonDown_1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0"/>
</Grid.ColumnDefinitions>
<Grid x:Name="Left" Grid.Column="1"/>
<Popup x:Name="pop"
Placement="Left"
PlacementTarget="{Binding ElementName=Left}"
Height="{Binding ActualHeight, ElementName=M}"
Width="{Binding ActualWidth, ElementName=M}">
<Grid Background="Red">
</Grid>
</Popup>
</Grid>
</Window>
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
namespace PopupTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void M_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
{
pop.IsOpen = !pop.IsOpen;
}
}
}
<Grid.RowDefinitions>
&nb