私は2つの部分クラス、ウィンドウA(frmSchedule)とウィンドウB(frmAddLesson)を持っています。ウィンドウAには、データバインドされたListViewコントロールがあります。ウィンドウAは新しいレッスンオブジェクトを作成するために設計されたウィンドウBを開き、そのレッスンデータをウィンドウAに戻したいと思います。これを達成する方法は何ですか? C#でアプリケーションスコープ変数を使用する簡単な方法はありますか?非親ウィンドウへのデータの送信
1つの基本クラスから両方の部分クラスを派生させ、そのクラスを使用してレッスンデータを最初のウィンドウに戻すことを試みましたが、わかりません。 :(詳細情報については
を、私はここでプログラムを打ち出してきました:
私はのObservableCollectionにバインドされたListViewコントロールとメインウィンドウ(fmrSchedule)を持っている: (単純化のために、私は」 btnAddボタンコントロールは、A開き
public partial class frmSchedule : Window
{
public frmSchedule()
{
InitializeComponent();
//ListView sample data
aLesson = new Lesson();
aLesson.Time = 9;
m_myLessons.Add(aLesson);
lstLessons.ItemsSource = LessonList;
}
Lesson aLesson;
private ObservableCollection<Lesson> m_myLessons = new ObservableCollection<Lesson>();
public ObservableCollection<Lesson> LessonList { get { return m_myLessons; } }
//Add Lesson
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
//New frmAddLesson window
frmAddLesson addLesson = new frmAddLesson();
addLesson.Show();
}
:レッスンオブジェクトは、重要データのみ1個)のコードで
<ListView Name="lstLessons" Margin="204,15,192,125" ItemsSource="{Binding Path=LessonList}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Time}">Time</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
を有するふりちゃいますメインウィンドウのレッスンリストに追加される新たなレッスンオブジェクトを作成するように機能する第2形態(frmAddLesson):(ここで、時間はコンボボックスの選択に基づいて設定されている)
public partial class frmAddLesson : Window
{
public frmAddLesson(System.DateTime? DateTime)
{
InitializeComponent();
dateTime = DateTime;
radPrivate.IsChecked = true;
}
//DateTime from calendar selection
private DateTime? dateTime;
//Lesson object
private Lesson theLesson;
//ADD LESSON
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
//Create new Lesson object
theLesson = new Lesson();
//Set Lesson property
theLesson.Time = (int)cmbTime.SelectedValue; //Time
this.Close();
}
}
レッスンクラス:
public class Lesson
{
public Lesson()
{
//Stuff for later
}
private int m_Time;
public int Time { get { return m_Time; } set { m_Time = value; } }
}
私は私はあなたがそれを行うことができますことを認識していなかったのか分からない...おかげでたくさん! –