WPF SizeChanged 事件不会触发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16750235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF SizeChanged event doesn't fire
提问by iAteABug_And_iLiked_it
This is a bit of a noob question.
这是一个有点菜鸟的问题。
Basically, I have a grid MainGridin my WPF window
基本上,MainGrid我的 WPF 窗口中有一个网格
I'd simply like to be notified when the MainGridis resized ( when user maximizes/resizes the window).
我只想在MainGrid调整大小时收到通知 (当用户最大化/调整窗口大小时)。
This does nothing at the moment. Am I supposed to declare and then add this SizeChanged event earlier before it will work?
目前这没有任何作用。我是否应该在它起作用之前先声明然后添加这个 SizeChanged 事件?
private void MainGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
MyTextBox.Text = "MainGrid resized";
}
Thank you
谢谢
回答by Rafal
If you have your event in code-behind and this in XAML:
如果您的事件在代码隐藏中并且在 XAML 中:
<Grid SizeChanged="MainGrid_SizeChanged">
it will work.
它会起作用。

