一.添加用户控件

1.在项目工程中添加-》新建项-》Silverlight用户控件(SilverlightControl.xaml)

 2.Page 页中
<UserControl x:Class="UserControlDemo.Page"
  xmlns:jl="clr-namespace:UserControlDemo;assembly=UserControlDemo">
使用:
 <jl:SilverlightControl x:Name="HomeAddress" />

 

二.清除用户控件的方法

1.用户控件部分

代码
public partial class SilverlightControl : UserControl
{
public class AddressEventArgs : RoutedEventArgs
{
public object Tag { get; set; }
public AddressEventArgs(object tag)
{
this.Tag=tag;
}
}
public delegate void AddressEventHandler(object o, AddressEventArgs e);
public event AddressEventHandler Closed;
void Close_Click(object sender, RoutedEventArgs e)
{
// remove this from the parent's children collection
Panel parent = this.Parent as Panel;
if (parent != null)
{
parent.Children.Remove(
this);
// alert the parent that we closed
if (Closed != null)
{
Closed(
this, new AddressEventArgs(this.Tag));
}
}
}
2.主页部分

代码
void Create_Click(object sender, RoutedEventArgs e)
{
SilverlightControl auc
= new SilverlightControl();
auc.Tag
= "1";
auc.Closed
+= new SilverlightControl.AddressEventHandler(auc_Closed);
MasterContainer.Children.Add(auc);
}
void auc_Closed(object o,SilverlightControl.AddressEventArgs e)
{
//Code用户控件关闭后的操作
}

 

相关文章:

  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2021-12-08
  • 2021-07-22
猜你喜欢
  • 2021-06-24
  • 2022-01-09
  • 2022-12-23
  • 2021-11-18
  • 2021-12-15
相关资源
相似解决方案