gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 18:13:25 25 4
gpt4 key购买 nike

我正在尝试实现 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com