我通过代码生成按钮。并使用按钮我有一个方法来调用silverlight中的子窗口。
private void btnXX_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
SlotMaker slotMaker = new SlotMaker();
slotMaker.Show();
}
当弹出子窗口时,我可能知道如何获得sender.content?从儿童窗口
答案 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属性。