在datagrid中使用了一个自定义控件,其中使用了Popup控件,其中用了ComboBox控件,Popup控件能打开,但一点击ComboBox控件Popup控件就自动关闭了,而不能选择里边的选项,不知道是什么原因。
XAML代码如下:
<UserControl x:Class="TestObjectDataProvider.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<StackPanel Margin="12,55,12,0" Name="stackPanel1" Orientation="Horizontal" Height="38" VerticalAlignment="Top">
<TextBox Height="23" Name="textBox1" Width="120" />
<Button Height="23" Name="button1" Width="75" Click="button1_Click">Button</Button>
<Popup Name="Popup1">
<ComboBox Height="23" Name="comboBox1" Width="120" /></Popup>
</StackPanel>
</Grid>
</UserControl>
后台代码如下:
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestObjectDataProvider
{
/// <summary>
/// UserControl1.xaml 的交互逻辑
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
this.Popup1.IsOpen = !this.Popup1.IsOpen;
}
}
}
以点击按钮时,可以显示出ComboBox,但在其中选择项目时,却直接关闭了弹出的Popup,不能选择,整个控件是放在datagrid的模板列中的,用于修改数据。
xiaojun