【问题标题】:Add different Content Views to a Content page (Rg.Popups) - Xamarin Forms将不同的内容视图添加到内容页面 (Rg.Popups) - Xamarin 表单
【发布时间】:2018-03-16 04:43:17
【问题描述】:

我在 Xamarin 表单中使用 Rg.Popups 创建了一个弹出页面。应用程序中的弹出窗口有不同的变体,理想情况下,我希望使用包含不同内容的相同弹出窗口。

<?xml version="1.0" encoding="UTF-8"?>
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="CustomKeyboard.Controls.CustomPopup"
    xmlns:local="clr-namespace:CustomKeyboard.Controls;assembly=CustomKeyboard"
    xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
 <StackLayout 
    VerticalOptions="Center" 
    HorizontalOptions="Center"
    BackgroundColor = "#00000000"
    Padding="20, 0, 20, 0">
    <Frame CornerRadius = "8"  VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
       <local:Content1 />
    </Frame>
</StackLayout>

这是一个内容视图及其静态。我需要内容视图是动态的。

所以当我导航到 CustomPopup 时,我应该能够指定我需要使用哪个 ContentView,并且弹出窗口需要呈现那个特定的内容视图。感谢有人可以提出一种巧妙的方法来实现这一点。

【问题讨论】:

    标签: c# xaml xamarin xamarin.forms


    【解决方案1】:

    我最终得到了这样的东西,它对我很有效。

    我只使用 c#(没有 xaml)创建了控件。但是你也可以这样做

    public class PDTPopup : Rg.Plugins.Popup.Pages.PopupPage
    {
        public PDTPopup(ContentView view)
        {
            Frame frame = new Frame
            {
                CornerRadius = 8,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Content = view
    
            };
            this.Content = new Xamarin.Forms.StackLayout()
            {
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromHex("#00000000"),
                Padding = new Thickness(20, 0, 20, 0),
                Children =
                {
                    frame
                }
            };
        }
    }
    

    然后,我需要在哪里调用弹出窗口。我愿意

    public Command PopupCommand
        {
            get
            {
                return new Command(async () => {
                    Content1Page view = new Content1Page();
                    await PopupNavigation.Instance.PushAsync(new CustomPopup(view));
                });
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-03
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      • 2012-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多