我想将在我的代码中添加对话框弹出窗口简化为所需的绝对最小值。
目前我有这个代码:
<pages:PopupPage
x:Class="Test.Popup"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
<ContentView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<t:PopupFrame>
<Label Text="ABC" />
<Label Text="ABC" />
</t:PopupFrame>
</ContentView>
</pages:PopupPage>
public partial class Popup : Rg.Plugins.Popup.Pages.PopupPage
{
public Popup()
{
InitializeComponent();
}
}
我在PopupFrame
这里:
[Xamarin.Forms.ContentProperty("Contents")]
public class PopupFrame : Frame
{
StackLayout contentStack { get; } = new StackLayout()
{
Spacing = 0,
Padding = new Thickness(0),
Orientation = StackOrientation.Vertical
};
public IList<View> Contents { get => contentStack.Children; }
public PopupFrame()
{
Content = contentStack;
HasShadow = true;
HorizontalOptions = LayoutOptions.FillAndExpand;
Padding = 0;
SetDynamicResource(BackgroundColorProperty, "PopUpBackgroundColor");
SetDynamicResource(CornerRadiusProperty, "PopupCornerRadius");
VerticalOptions = LayoutOptions.Center;
}
}
任何人都可以提出一种方法,我可以将这两者结合起来,以便只需要以下内容:
<t:PopupPage
x:Class="Test.Popup"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:t="clr-namespace:Test.Templates">
<Label Text="ABC" />
<Label Text="ABC" />
</pages:PopupPage>
所以我正在寻找的是内容:
[Xamarin.Forms.ContentProperty("Contents")]
public class Popup : Rg.Plugins.Popup.Pages.PopupPage
{
}
更新:这是我根据建议的答案尝试过的:
<?xml version="1.0" encoding="UTF-8" ?>
<pages:PopupPage
x:Class="Memorise.DecksTab.CopyDeckPopup"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
<Label Text="ABC" />
<Label Text="ABC" />
</pages:PopupPage>
带有支持代码:
[Xamarin.Forms.ContentProperty("Contents")]
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CopyDeckPopup : Rg.Plugins.Popup.Pages.PopupPage
{
PopupFrame contentFrame { get; } = new PopupFrame();
public IList<View> Contents { get => contentFrame.Contents; }
public CopyDeckPopup(string clickedDeckName, string clickedDeckDescription)
{
BindingContext = new CopyDeckPopupViewModel(clickedDeckName, clickedDeckDescription);
InitializeComponent();
Content = new ContentView()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Content = contentFrame
};
}
}
它给了我这个错误,但显示是正确的,我看到两个 ABC。