2011-11-10 10 views
1

コードでボタンを生成しました。ボタンを使って、私は銀色で子ウィンドウを呼び出す1つの方法を得ました。子ウィンドウから送信者(ボタン)を取得する

private void btnXX_Click(object sender, RoutedEventArgs e) 
    { 
     Button btn = (Button)sender; 
     SlotMaker slotMaker = new SlotMaker(); 
     slotMaker.Show(); 
    } 

子供のウィンドウがポップアップしている間、私はどのように私がsender.contentを得ることができますか?子ウィンドウ

+0

ボタンのテキストを意味しますか?または、ボタンにもっと複雑なコンテンツがありますか? –

+0

ボタンのテキストは日付時間です – 1myb

答えて

1

から

public DateTime SlotDateTime {get; private set; } 

public SlotMaker(DateTime slotDateTime) 
{ 
     SlotDateTime = slotDateTime; 
     InitializeComponent(); 
     // Modify some display using value of SlotDateTime 
} 

SlotMakerコンストラクタを変更します次に、あなたのボタンで簡単に.NETとして解析し、あなたのXAMLの文字列を配置するために、ボタンのTagプロパティを使用し

private void btnXX_Click(object sender, RoutedEventArgs e)  
{  
    Button btn = (Button)sender; 
    DateTime dateTime = btn.Tag; // OR = DateTime.Parse(btn.Tag)  
    SlotMaker slotMaker = new SlotMaker(dateTime);  
    slotMaker.Show();  
} 

をクリックしてくださいDateTimeを使用するか、コードを使用して実際のDateTimeをTagプロパティに割り当てます。

+0

素晴らしい!働いている= D Thx – 1myb

関連する問題