【问题标题】:Get sender (button) from child window从子窗口获取发件人(按钮)
【发布时间】:2011-11-10 19:47:26
【问题描述】:

我是通过代码生成按钮的。使用按钮,我有一种方法可以在 Silverlight 中调用子窗口。

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

当子窗口弹出时,我可以知道如何获取 sender.content 吗?从子窗口

【问题讨论】:

  • 你的意思是按钮文本吗?还是按钮中有更复杂的内容?

标签: silverlight button childwindow sender


【解决方案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 属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 2021-09-03
    相关资源
    最近更新 更多