如何使用 MVVMCross 显示模态弹出窗口
How to display modal popover using MVVMCross
我正在尝试使用 Xamarin.iOS 和 MVVMCross 显示模态弹出窗口。
这是我的观点:
[MvxModalPresentation(
WrapInNavigationController = true,
ModalPresentationStyle = UIModalPresentationStyle.Popover,
PreferredContentSize = new CGSize(100, 100)
)]
public class Test2View : BaseViewController<TestView2Model>
{
//other code...
}
这无法编译。 PreferredContentSize 属性有错误。
'PreferredContentSize' is not a valid named attribute argument because it has type 'CoreGraphics.CGSize', which is not a valid attribute parameter type
作为后续问题,有没有办法在 iPhone 上设置特定大小的模态弹出窗口?
解释了它无法编译的原因here:
This is a CLR restriction. Only primitive constants or arrays of primitives can be used as attribute parameters. The reason why is that an attribute must be encoded entirely in metadata. This is different than a method body which is coded in IL. Using MetaData only severely restricts the scope of values that can be used. In the current version of the CLR, metadata values are limited to primitives, null, types and arrays of primitives (may have missed a minor one).
您可以使用更适合您的用例的不同 UIModalPresentationStyle
。您可以找到有关每种样式的更多信息 here(请参阅 'Presentations' 部分)。
如果 none 满足您的需要,但您仍然希望弹出窗口具有特定大小,您可以试试这个:
[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);
}
}
我正在尝试使用 Xamarin.iOS 和 MVVMCross 显示模态弹出窗口。
这是我的观点:
[MvxModalPresentation(
WrapInNavigationController = true,
ModalPresentationStyle = UIModalPresentationStyle.Popover,
PreferredContentSize = new CGSize(100, 100)
)]
public class Test2View : BaseViewController<TestView2Model>
{
//other code...
}
这无法编译。 PreferredContentSize 属性有错误。
'PreferredContentSize' is not a valid named attribute argument because it has type 'CoreGraphics.CGSize', which is not a valid attribute parameter type
作为后续问题,有没有办法在 iPhone 上设置特定大小的模态弹出窗口?
解释了它无法编译的原因here:
This is a CLR restriction. Only primitive constants or arrays of primitives can be used as attribute parameters. The reason why is that an attribute must be encoded entirely in metadata. This is different than a method body which is coded in IL. Using MetaData only severely restricts the scope of values that can be used. In the current version of the CLR, metadata values are limited to primitives, null, types and arrays of primitives (may have missed a minor one).
您可以使用更适合您的用例的不同 UIModalPresentationStyle
。您可以找到有关每种样式的更多信息 here(请参阅 'Presentations' 部分)。
如果 none 满足您的需要,但您仍然希望弹出窗口具有特定大小,您可以试试这个:
[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);
}
}