【问题标题】:Windows Forms UserControl + Panel: WPF EquivalentWindows 窗体 UserControl + 面板:WPF 等效项
【发布时间】:2012-02-13 17:06:30
【问题描述】:

在 Windows 窗体中,我创建了一个 Twitter 应用程序,该应用程序使用 TweetSharp 从时间轴获取最新推文。我使用了UserControlPanel 来显示这些。我用来执行此操作的代码如下所示:

IEnumerable<TwitterStatus> tweets = service.ListTweetsOnHomeTimeline();

foreach (var tweet in tweets)
{
    TweetBox t = new TweetBox();

    t.username.Text = tweet.User.ScreenName; // Label
    t.display.ImageLocation = tweet.User.ProfileImageUrl; // PictureBox
    t.tweet.Text = tweet.Text; // Label
    t.info.Text = tweet.CreatedDate.ToString();
    t.Dock = DockStyle.Top;
    HomeTimeline.Controls.Add(t); // Add to HomeTimeline Panel
}

我现在正在 WPF 中重新制作这个应用程序。 UserControl 的格式相同,但我不知道如何将它添加到面板并将其停靠在顶部 - 或 WPF 中的等价物。我该怎么做呢?

【问题讨论】:

标签: c# wpf user-controls tweetsharp


【解决方案1】:

WinForms 用户控件与 WPF 用户控件不同。

您必须在 WPF 中再次创建 UserControl。

当然,您可以将 WinForms UserControl 包装在 WindowsFormsHost 元素中,但这不是好的做法。

【讨论】:

  • 我拥有的用户控件是 wpf 用户控件
  • 一定忽略了这一点。无论如何,WPF 中的 GUI 是在 XAML 中完成的。 (虽然它可以在代码隐藏中完成,但这也不是一个好习惯)
猜你喜欢
  • 2010-10-03
  • 2017-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-03
  • 1970-01-01
相关资源
最近更新 更多