Wpf 用户控件Load事件执行两次

<!--主窗体,放置一个用户控件-->
<Window x:Class="WpfApplication.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wpfApplication="clr-namespace:WpfApplication" Title="MainWindow" Height="350" Width="525"> <Grid> <wpfApplication:UserControl1></wpfApplication:UserControl1> </Grid> </Window>
//用户控件
namespace
WpfApplication { /// <summary> /// UserControl1.xaml 的交互逻辑 /// </summary> public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void UserControl1_OnLoaded(object sender, RoutedEventArgs e) {
       //为毛执行两次? StackTrace trace
= new StackTrace(); MessageBox.Show(trace.ToString()); } } }

 

你可能感兴趣的:(Wpf 用户控件Load事件执行两次)