1

我有一个用 WPF 制作的自定义控件,其中ControlTemplate包含一个Popup控件:

<Popup x:Name="PART_Popup" 
       PopupAnimation="Fade"
       Width="{TemplateBinding Width}"
       AllowsTransparency="True"
       IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsPopupOpen, Mode=OneWay}" 
       Placement="Bottom"  
       PlacementTarget="{Binding ElementName=PART_Border}">

自定义控件由以下代码托管在 WinForms 应用程序中:

var wpfHost = new ElementHost();
wpfHost.Dock = DockStyle.Fill;
wpfHost.Child = new TitleBar();
Controls.Add(wpfHost);

当窗口位置发生变化时,我想使弹出窗口重新定位。我在这里看到了几个答案,建议获取窗口参考并注册他的LocationChanged活动,但它对我不起作用,因为它托管在 winForms 窗口中。

任何的意见都将会有帮助 :)

4

1 回答 1

2

您不能只通过?:连接到LocationChanged活动吗?ElementHost

TitleBar课堂上:

public void WinFormsParent_LocationChanged(object sender, EventArgs e)
{
    // Do what you want here
}

在托管代码中:

var wpfHost = new ElementHost();
wpfHost.Dock = DockStyle.Fill;
TitleBar titleBar = new TitleBar();
LocationChanged += titleBar.WinFormsParent_LocationChanged;
wpfHost.Child = titleBar;
Controls.Add(wpfHost);
于 2013-10-24T10:22:39.107 回答