WPF 热重载失效了

关于

热重载官方说明:

  • WPF 和 UWP 应用的 XAML 热重载是什么
  • Introducing the .NET Hot Reload experience for editing code at runtime

热重载简单来说,就是点击运行程序后,修改 XAML 代码,应用程序会实时的显示你的修改

为什么热重载失效了?

排查参考官方文档:XAML 热重载疑难解答

我在排查的时候,发现 XAML 设计器给我报了如下一个警告,我发现删掉这个后,热重载就能用了
WPF 热重载失效了_第1张图片
那这种情况该如何处理?

可以把 EventSetter 放到代码里处理,参考:how-to-add-eventsetter-by-code

private static Style SearchBoxListItemContainerStyle { get; set; }

static Init()
{
	SearchBoxListItemContainerStyle = (System.Windows.Style)this.Resources["SearchBoxListItemContainerStyle"];
    EventSetter eventSetter = new EventSetter()
    {
        Event = ListBoxItem.MouseDoubleClickEvent,
        Handler = new MouseButtonEventHandler(ListBoxItem_MouseDoubleClick)
    };
    SearchBoxListItemContainerStyle.Setters.Add(eventSetter);
}

void foo()
{
	ListBox listBox;
	// ...
	listBox.ItemContainerStyle = SearchBoxListItemContainerStyle;
}

你可能感兴趣的:(wpf,microsoft)