我有一个使用Wpf + Blazor的dotnet-7 windows应用程序。
我的问题是我无法从window
导航到razor page
我的MainWindow.xaml
:
<Button Content="Open" Click="OpenOnClick" />
MainWindow.xaml.cs
:
public partial class MainWindow : Window
{
public MainWindow()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddWpfBlazorWebView();
#if DEBUG
serviceCollection.AddBlazorWebViewDeveloperTools();
#endif
Resources.Add("services", serviceCollection.BuildServiceProvider());
InitializeComponent();
}
private void OpenOnClick(object sender, RoutedEventArgs e)
{
new EditingWindow().Show();
}
}
EditingWindow.xaml
:
<Window x:Class="CodeEditor.EditingWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:blazor="clr-namespace:Microsoft.AspNetCore.Components.WebView.Wpf;assembly=Microsoft.AspNetCore.Components.WebView.Wpf"
xmlns:local="clr-namespace:CodeEditor"
mc:Ignorable="d"
Title="EditingPage" Height="450" Width="800">
<Grid>
<blazor:BlazorWebView HostPage="wwwroot/index.html" Services="{DynamicResource services}">
<blazor:BlazorWebView.RootComponents>
<blazor:RootComponent Selector="#app" ComponentType="{x:Type local:IndexEditor}" />
</blazor:BlazorWebView.RootComponents>
</blazor:BlazorWebView>
</Grid>
</Window>
而razor页面本身只是一个<h1>
标签和后面的空代码:IndexEditor.razor
IndexEditor.razor.cs
index.html
是常规的blazor样板:
...head
<body>
<div id="app">Loading...</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webview.js" autostart="false"></script>
</body>
当我点击按钮,窗口显示出来,但它是空的,它有我在EditingWindow.Xaml
中设置的标题,这是EditingPage
,但它是空的,我认为问题是它不能服务于剃刀页面,但IDK为什么,我也尝试了不同的导航方式,但没有一个有任何区别。
1条答案
按热度按时间zhte4eai1#
您需要将“services”
ServiceProvider
资源添加到托管BlazorWebView
的EditingWindow
: