我正在玩 .Net Maui。我想将地图添加到我的演示应用程序中。不幸的是,地图控件似乎还没有迁移。此外,承诺的控制实施似乎已从 RC 路线图中删除。
还有像这样的现有项目: https: //github.com/amay077/Xamarin.Forms.GoogleMaps 不支持 .Net Maui...
有人已经包含了 .Net Maui 项目的地图并且可以给我一些提示吗?
谢谢!
我正在尝试 .Net Maui、AppShell 和依赖注入。
我尝试使用构造函数调用页面,该构造函数将此页面的 ViewModel 作为参数。
构造函数如下所示:
public AuthenticationPage(AuthenticationViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
}
Run Code Online (Sandbox Code Playgroud)
在我的 MauiProgram.cs 中,我注册了页面和虚拟机
builder.Services.AddSingleton<AuthenticationViewModel>();
builder.Services.AddSingleton<AuthenticationPage>();
Run Code Online (Sandbox Code Playgroud)
我的 App.xaml.cs 如下所示:
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new AppShell();
}
}
Run Code Online (Sandbox Code Playgroud)
我的 AppShell.xaml 如下所示:
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:DeepBlue.Pages"
xmlns:auth="clr-namespace:DeepBlue.Pages.Authentication"
x:Class="DeepBlue.AppShell">
<!-- Login and Registration Page -->
<ShellContent Route="login"
ContentTemplate="{DataTemplate auth:AuthenticationPage}">
</ShellContent>
<!-- Main Page -->
<FlyoutItem Route="main"
FlyoutDisplayOptions="AsMultipleItems">
<ShellContent Route="dashboard"
ContentTemplate="{DataTemplate pages:DashboardPage}"
Title="Home" />
</FlyoutItem>
</Shell>
Run Code Online (Sandbox Code Playgroud)
现在,当我执行我的项目时,出现以下错误:
System.MissingMethodException:“没有为类型‘DeepBlue.Pages.Authentication.AuthenticationPage’定义无参数构造函数。”
有人可以告诉我为什么依赖注入在这种情况下不起作用吗? …
在我的 .Net Maui 项目中,我在 ControlTemplate 中使用 CollectionView。实现看起来像这样:
<ContentView.ControlTemplate>
<ControlTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<SearchBar
x:Name="ObjectSearchBar"
Grid.Row="0"
IsSpellCheckEnabled="False"
Keyboard="Text"
Placeholder="{TemplateBinding SearchBarPlaceholderText}"
TextChanged="ObjectSearchBar_TextChanged" />
<CollectionView
x:Name="ObjectResultView"
Grid.Row="1"
Margin="10,10,10,10"
ItemSizingStrategy="MeasureAllItems"
ItemTemplate="{StaticResource templateSelector}"
ItemsLayout="VerticalList"
ItemsSource="{TemplateBinding DataSource}"
SelectionChanged="ObjectResultView_SelectionChanged"
SelectionMode="Single">
</CollectionView>
</Grid>
</ControlTemplate>
<ContentView.ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
我在 ContentPage 中使用此 ContentView。该页面包含 2 个 StackLayout,其实现如下所示:
<ContentPage.Content>
<Grid>
<StackLayout
HorizontalOptions="FillAndExpand"
IsVisible="{Binding AddNewSectionIsVisible, Converter {converter:InvertedBoolConverter}}"
Orientation="Vertical"
VerticalOptions="FillAndExpand">
<controls:ObjectSearchControl
DataSource="{Binding DataSource}"
FilterChangedCommand="{Binding FilterChangedCommand}"
HorizontalOptions="FillAndExpand"
ObjectSelectedCommand="{Binding SelectedCommand}"
SearchBarPlaceholderText="ABC"
VerticalOptions="FillAndExpand" />
</StackLayout>
<StackLayout
HorizontalOptions="FillAndExpand"
IsVisible="{Binding AddNewSectionIsVisible}"
Orientation="Vertical"
Style="{StaticResource rootStackLayout}"
VerticalOptions="Center"> …Run Code Online (Sandbox Code Playgroud)