从子窗口获取发件人(按钮)

时间:2011-11-10 11:21:36

标签: silverlight button childwindow sender

我通过代码生成按钮。并使用按钮我有一个方法来调用silverlight中的子窗口。

   private void btnXX_Click(object sender, RoutedEventArgs e)
    {
        Button btn = (Button)sender;
        SlotMaker slotMaker = new SlotMaker();
        slotMaker.Show();
    }
当弹出子窗口时,我可能知道如何获得sender.content?从儿童窗口

1 个答案:

答案 0 :(得分:1)

SlotMaker构造函数修改为

 public DateTime SlotDateTime {get; private set; }

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

然后在按钮中单击

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();     
}

使用按钮Tag属性在Xaml中放置一个字符串,可以轻松解析为.NET DateTime,或者使用代码将实际DateTime分配给Tag属性。