c# - 在 Asp.net core 上实现 Ooui

标签 c# xamarin.forms

我正在尝试实现 Ooui 以使我的 View 模型支持 ASP.NET Core 并以 Web 为目标。我有一个跨 WPF 共享的类库,Xamarin.Forms 使用 MvvmLight 框架。所以我尝试为 ooui 找到更好的方法。一个建议将不胜感激。现在我无法让 DisplayAlert 在每个页面上工作。

public class BaseController : Controller, IDialogService, INavigationService
{
    private static Stack<Page> _stack = null;

    protected Page CurrentPage => page.Navigation.NavigationStack.LastOrDefault();
    protected Page RootPage => page.Navigation.NavigationStack.FirstOrDefault();

    static BaseController()
    {
        _stack = new Stack<Page>();
    }

    private IHttpContextAccessor _service;
    private IApplicationBuilder app;
    protected NavigationPage page;


    private HttpContext Context
    {
        get { return _service.HttpContext; }
    }

    public string CurrentPageKey => throw new NotImplementedException();

    public BaseController()
    {
        if (!SimpleIoc.Default.IsRegistered<IDialogService>())
            SimpleIoc.Default.Register<IDialogService>(() => this);

        if (!SimpleIoc.Default.IsRegistered<INavigationService>())
            SimpleIoc.Default.Register<INavigationService>(() => this);

        _service = SimpleIoc.Default.GetInstance<IHttpContextAccessor>();
        app = SimpleIoc.Default.GetInstance<IApplicationBuilder>();
    }

    public async Task ShowError(string message, string title, string buttonText, Action afterHideCallback)
    {
        await CurrentPage.DisplayAlert(title, message, buttonText);
        afterHideCallback();
    }

    public async Task ShowError(Exception error, string title, string buttonText, Action afterHideCallback)
    {
        await CurrentPage.DisplayAlert(title, error.Message, buttonText);
        afterHideCallback();
    }

    public async Task ShowMessage(string message, string title)
    {
        await CurrentPage.DisplayAlert(title, message, "OK");
    }

    public async Task ShowMessage(string message, string title, string buttonText, Action afterHideCallback)
    {
        await CurrentPage.DisplayAlert(title, message, buttonText);
        afterHideCallback();
    }

    public async Task<bool> ShowMessage(string message, string title, string buttonConfirmText, string buttonCancelText, Action<bool> afterHideCallback)
    {
        var result = await page.DisplayAlert(title, message, buttonConfirmText, buttonCancelText);
        afterHideCallback(result);
        return result;
    }

    public async Task ShowMessageBox(string message, string title)
    {
        await CurrentPage.DisplayAlert(title, message, "OK");
    }

    public void GoBack()
    {
        page.PopAsync();
        page.PushAsync(_stack.Pop());
    }

    public void NavigateTo(string pageKey)
    {
        _stack.Push(CurrentPage);

        page.PopAsync();            
        page.PushAsync(SimpleIoc.Default.GetInstance<Page>(pageKey));
    }

    public void NavigateTo(string pageKey, object parameter)
    {
        throw new NotImplementedException();
    }
}



public class HomeController : BaseController
    {        
        public HomeController()
            : base()
        {
            SimpleIoc.Default.Register<Page>(() => new Next(), "Next");
            SimpleIoc.Default.Register<Page>(() => new MainPage(), "MainPage");
        }

        public IActionResult Index()
        {
            page = new NavigationPage(new MainPage());            
            //NavigateTo("MainPage");
            return new ElementResult(page.GetOouiElement(), "Hello from XAML!");
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

最佳答案

根据您的评论,我的假设是正确的。

对话框渲染了,但是它没有显示在前面。 定义 CSS 属性 z-index在元素上显然解决了这个问题。

如果以 HTML 形式给出...

<div class="most-top"> ... </div>

.. 你的 css 可能看起来像这样..

.most-top {
    z-index: 99;
}

关于c# - 在 Asp.net core 上实现 Ooui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52411646/

相关文章:

c# - 如何在 xamarin.forms 中添加带有 retrofit 的静态授权 header ?

.net - Xamarin项目的Targeted Framework如何改成4.0

c# - 使用下载服务将 IsRefreshing 绑定(bind)到 IsBusy

c# - Xamarin iOS - 基于配置文件的代码

c# - WebClient网站登录

c# - 如何在 C# 中打开和检测 exe 的关闭

c# - 将 MyClass 的列表显示到 DataGridView

c# - Xamarin.forms 上的后台获取

c# - 发布网站时出现 Angular 未知提供商错误

c# - 在 winRT MessageDialog 中添加 TextBox