簡體   English   中英

在Winforms中使用WPF自定義控件

[英]using a WPF custom control in Winforms

我在Winforms中制作了wpf自定義控件。 我正在使用元素主機將wpf控件嵌入到Winforms中。

我的wpf自定義控件中有幾個不同的橢圓,它們都有鼠標按下事件處理程序,在運行時我單擊了一個橢圓,我可以更改它們的顏色,但是我的問題是如何查看我的信息從我的WPF Winform應用程序?

我嘗試了這個:

private void elementHost1_ChildChanged(object sender, System.Windows.Forms.Integration.ChildChangedEventArgs e)
    {
        int stop =0;
    }
  private void Ellipse_MouseDown(object sender, MouseButtonEventArgs e)
    {
        Ellipse EP = sender as Ellipse;
        string tempS = EP.Name;
        EP.Fill = Brushes.Green;

        int you = 0;
    }
}

另外,如果調用了處理程序,我不確定如何學習哪個Ellipse也調用了它,是否有辦法從Winform更改Ellipse的顏色?

您可以使用事件來做到這一點。 為您的wpf控件創建一個事件,並在單擊時引發它,然后在winform中向該事件添加處理程序並監聽該事件。

用於創建事件:

public event Action OnEllipseClick;

為了提高它:

this.OnEllipseClick?.Invoke();

如果winform用於綁定事件:

this.userControl11.OnEllipseClick += UserControl11_OnEllipseClick;

private void UserControl11_OnEllipseClick()
{
    MessageBox.Show("hi");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM