The following code won't work:
RoutedEventHandler handler = (sender, eventArgs) =>
{
var ui = sender as UIElement;
ui.Visibility = Visibility.Collapsed;
control.Click -= handler;
};the compiler complains the handler is not initialized.
But this code will shut up the compiler:
RoutedEventHandler handler = null;
handler = (sender, eventArgs) =>
{
var ui = sender as UIElement;
ui.Visibility = Visibility.Collapsed;
control.Click -= handler;
};funny.
本文探讨了WPF应用程序中一个特定的事件处理器初始化问题。通过对比两种不同的实现方式,展示了如何避免编译器关于未初始化的警告。文章最终提供了一种可行的解决方案,确保事件处理器能够正确地被定义并使用。
788

被折叠的 条评论
为什么被折叠?



