刷新方向更改的控件

本文关键字:控件 方向 刷新 | 更新日期: 2023-09-27 17:59:57

我有一个自定义面板控件,内置在MainPage.xaml.cs中,我希望它在方向改变时重新绘制自己(因为它需要测量显示的宽度来查看我需要它的样子)。我还没有找到任何在线方法:/

刷新方向更改的控件

在类中声明

private SimpleOrientationSensor _orientationSensor;

那就这样用吧

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

_orientationSensor必须是类的成员,否则将由GC收集,并且事件不会触发