我們有一些代碼是我們在.net 4.0的WPF項目上試用過的,它使用了Windows,但是我們重新啓動了項目以將所有內容組合在一起,現在我們已經開始利用UserControls了。與我以前的代碼一起工作的我的窗口不適用於這個新的UserControl代碼,它說明了我在標題中發佈的內容。如何爲Usercontrol添加using指令或程序集引用。
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfPrototype1Screens
{
/// <summary>
/// Interaction logic for Screen_1.xaml
/// </summary>
public partial class Screen_1 : UserControl
{
public Screen_1()
{
this.InitializeComponent();
}
protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(e);
FrameworkElement element = e.OriginalSource as FrameworkElement;
if(element.DataContext is DateTime){
DateTime date = (DateTime) element.DataContext;
WpfPrototype1Screens.Add_Event addEvent = new Add_Event(date);
addEvent.Show();
addEvent.Focus();
}
}
}
}
問題出現在OnMouseDoubleClick
事件方法的最後2行。焦點顯示爲正常,但addEvent.Show();
沒有。它說這種類型的Usercontrol沒有Show()這樣的事情。
現在我發現有不同的用戶控件...有一個我試圖引用(右擊 - >添加引用 - > .net選項卡 - >並選擇System.Windows。 Forms(); ...但沒有工作,因爲我意識到我們正在使用的UserControl不是一個「形式」的用戶控件,它是一個Usercontrol控件?我猜?我不知道該怎麼做才能做到這一點代碼編譯和工作
請使用代碼塊格式化代碼。這是不可讀的。 – 2010-09-30 18:14:37
請格式化您的代碼 - 編輯此帖子,選擇代碼,然後按代碼圖標。這樣閱讀是非常困難的。 – 2010-09-30 18:15:05
你能發佈異常嗎? – Yogesh 2010-09-30 19:05:50