Refresh control on orientation change?

时间:2015-06-26 09:59:00

标签: c# xaml windows-runtime windows-phone-8.1 refresh

I have a custom panel control, built in MainPage.xaml.cs, and I want it to redraw itself when the orientation changes (because it needs to measure the width of the display to look how I need it). I haven't found any way how to do this anywhere online :/

1 个答案:

答案 0 :(得分:1)

在你的班级中宣布这一点

_orientationSensor = SimpleOrientationSensor.GetDefault();
        if (_orientationSensor != null)
        {
            _orientationSensor.OrientationChanged += delegate 
            {
                 // do whatever you need here
            };
        }

然后像这样使用它

{{1}}

_orientationSensor必须是类的成员,否则将被GC收集并且事件不会被激活