Xamarin.ios 如何使用MVVMCross显示模式popover

Xamarin.ios 如何使用MVVMCross显示模式popover,xamarin.ios,mvvmcross,Xamarin.ios,Mvvmcross,我正在尝试使用Xamarin.iOS和MVVMCross显示一个模式popor 以下是我的看法: [MvxModalPresentation( WrapInNavigationController = true, ModalPresentationStyle = UIModalPresentationStyle.Popover, PreferredContentSize = new CGSize(100, 100) )] public class

我正在尝试使用Xamarin.iOS和MVVMCross显示一个模式popor

以下是我的看法:

[MvxModalPresentation(
        WrapInNavigationController = true,
        ModalPresentationStyle = UIModalPresentationStyle.Popover,
        PreferredContentSize = new CGSize(100, 100)
)]
public class Test2View : BaseViewController<TestView2Model>
{
    //other code...
}

作为后续问题,有没有办法在iPhone上安装特定尺寸的模式popover?

解释了它无法编译的原因:

这是一个CLR限制。只有基元常量或基元数组可以用作属性参数。原因是属性必须完全在元数据中编码。这与用IL编码的方法体不同。使用元数据只会严重限制可以使用的值的范围。在当前版本的CLR中,元数据值仅限于原语、null、原语类型和数组(可能缺少一个较小的)

您可以使用不同的
UIModalPresentationStyle
,它更适合您的用例。您可以找到有关每种样式的更多信息(请参阅“演示文稿”一节)

如果没有一个适合您的需要,并且您仍然希望弹出窗口具有特定的大小,您可以尝试以下方法:

[MvxModalPresentation(WrapInNavigationController = true, ModalPresentationStyle = UIModalPresentationStyle.Popover)]
public class Test2View : BaseViewController<TestView2Model>
{
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        // Set your specific size
        PreferredContentSize = new CGSize(300, 300);
    }
}
[MvxModalPresentation(WrapInNavigationController=true,ModalPresentationStyle=UIModalPresentationStyle.Popover)]
公共类Test2View:BaseViewController
{
公共覆盖无效ViewDidLoad()
{
base.ViewDidLoad();
//设置您的具体尺寸
PreferredContentSize=新的CGSize(300300);
}
}

我刚试过这个。它可以编译,但在我的iPhone模拟器上没有popover。注意:iPhone而不是iPad模拟器。在我在回答中提供的
UIModalPresentationStyle
文档中,您可以发现在水平紧凑的环境中
UIModalPresentationStyle.Popover
的行为与
UIModalPresentationStyle.fullScreen
相同。你可以试试其他的选择,看看哪一个适合你的需要……是的。我想我需要弄清楚我是如何在本机iOS环境中做到这一点的。我将把这个答案标为正确。
[MvxModalPresentation(WrapInNavigationController = true, ModalPresentationStyle = UIModalPresentationStyle.Popover)]
public class Test2View : BaseViewController<TestView2Model>
{
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        // Set your specific size
        PreferredContentSize = new CGSize(300, 300);
    }
}