标签: maui

.net Maui 数据绑定到 shell 弹出项 IsVisible 属性

所以我有一个弹出菜单,我需要使弹出项目在某些条件下消失。为了帮助我发展我的想法和理解,我有一个包含 6 个项目的弹出窗口,其中之一的标题是蓝牙。我在第一个弹出页面中创建了一个名为 ShowParameters 的按钮。我可以使视图模型中的属性为 true 或 false。这似乎工作正常。我已将蓝牙弹出项目的 IsVisible 属性绑定到此 ShowParameters 属性。这不会在单击按钮时更新 IsVisible 属性。似乎 PropertyChanged?.Invoke 未链接到 Flyout 项目,或者 Flyout 项目未链接到该属性,尽管我可以使其在 xaml 本身中出现或消失。显然,作为一个菜鸟,我做了一些非常愚蠢的事情。有人可以指出我有多愚蠢吗;)

AppShell.xaml

<?xml version="1.0" encoding="UTF-8" ?>
<Shell
    x:Class="TSDZ2Monitor.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:sys="clr-namespace:System;assembly=netstandard"
  
    xmlns:local="clr-namespace:TSDZ2Monitor"

    xmlns:pages="clr-namespace:TSDZ2Monitor.Pages"
  
    Shell.FlyoutBehavior="Flyout"
    FlyoutHeaderBehavior="Default"
    FlyoutVerticalScrollMode="Auto"
    FlyoutBackgroundColor="{StaticResource FlyoutBackgroundColor}">

  <Shell.BindingContext>
    <local:ShowParametersViewModel/>
  </Shell.BindingContext>

  <Shell.FlyoutHeaderTemplate>
    <DataTemplate>
      <Grid BackgroundColor="{StaticResource FlyoutBackgroundColor}"
            HeightRequest="200">
        <Image 
               HeightRequest="200"
               Source="bicycle.svg"
               Margin="10, 10, 10, 10"
               Opacity="0.6" />
        <Label Text="TSDZ2 Monitor"
               TextColor="White"
               FontAttributes="Bold" />
      </Grid>
    </DataTemplate>
  </Shell.FlyoutHeaderTemplate>

  <Shell.FlyoutFooterTemplate>
    <DataTemplate>
      <StackLayout>
        <Label Text="TSDZ2"
               TextColor="GhostWhite"
               FontAttributes="Bold"
               HorizontalOptions="Center" />
        <Label Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{0:MMMM …
Run Code Online (Sandbox Code Playgroud)

.net data-binding shell maui

3
推荐指数
1
解决办法
3175
查看次数

.net maui MVVM 从 CollectionView 绑定 SelectedItemCommand 和 SelectedItemParameter

所以我正在使用 SQLite、CommunityToolkit.Mvvm.ComponentModel;

我有一个包含朋友表的数据库。我可以将其绑定到 CollectionView。我正在关注https://www.youtube.com/watch?v=8_cqUvriwM8但尝试使用 MVVM 方法。

我可以让它与 SelectionChanged 和事件一起愉快地工作,但不能与 SelectionChangedCommand 一起工作,并且我无法访问列表中的好友项目。

这是相关的xaml

    <CollectionView Grid.Row="2"
                    x:Name="FriendsList"
                    SelectionMode="Single"
                    SelectionChangedCommand="{Binding SelectionChangedCommand}" 
                    SelectionChangedCommandParameter="{Binding .}"
                    SelectionChanged="OnSelectionChanged" >
Run Code Online (Sandbox Code Playgroud)

这是代码的相关部分(我使用 xaml 后面的代码只是为了测试)

    public MainPage()
    {
        InitializeComponent();

    this.BindingContext = this;  //cool for binding the xaml to the code behind.
  }
...


//This works fine (so why do I bother with mvvm?)
  public void OnSelectionChanged(Object sender, SelectionChangedEventArgs e)
  {
    Console.WriteLine("Selection changed click");
    Friend f = e.CurrentSelection[0] as Friend;
    Console.WriteLine(f.LName);
  }

//Can't get this to work, though it …
Run Code Online (Sandbox Code Playgroud)

collectionview maui

3
推荐指数
3
解决办法
8790
查看次数

如何使用 Microsoft.Maui.Essentials?

如何在我的 MAUI 应用程序中设置 Microsoft.Maui.Essentials?我读到它默认随我安装的 .NET 6 一起提供,但每当我使用 Microsoft.Maui.Essentials 时;出现错误消息:

The type or namespace name 'Essentials' does not exist in the namespace 'Microsoft.Maui' (are you missing an assembly reference
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助。

maui

3
推荐指数
1
解决办法
5120
查看次数

.Net MAUI 数据绑定未传递到自定义组件

我在数据绑定与自定义组件一起使用时遇到问题。

我创建了一个 IncrementValue 属性,每次单击按钮时该属性都会增加。

绑定到标签时会反映更改。但是,当我将其绑定到自定义组件中的可绑定属性时,它们不起作用。

在示例中,我构建了一个名为的自定义组件Card,它具有两个可绑定属性CardTitleCardIncrement

由于我是 MAUI 甚至 Xamarin 的新手,我是否遗漏了一些东西。

以下代码片段的 Github 链接:https://github.com/814k31/DataBindingExample

卡.xaml.cs

namespace DataBindingExample;

public partial class Card : VerticalStackLayout
{
    public static readonly BindableProperty CardTitleProperty = BindableProperty.Create(nameof(CardTitle), typeof(string), typeof(Card), string.Empty);
    public static readonly BindableProperty CardIncrementProperty = BindableProperty.Create(nameof(CardIncrement), typeof(int), typeof(Card), 0);

    public string CardTitle
    {
        get => (string)GetValue(CardTitleProperty);
        set => SetValue(CardTitleProperty, value);
    }

    public int CardIncrement
    {
        get => (int)GetValue(CardIncrementProperty);
        set => SetValue(CardIncrementProperty, value);
    }

    public Card()
    {
        InitializeComponent();

        BindingContext = …
Run Code Online (Sandbox Code Playgroud)

maui

3
推荐指数
1
解决办法
2915
查看次数

如何清除 Xamarin/MAUI 中的导航?

我有以下应用程序结构:

Main Page : Choose Login Type A or B

if the user choses login type A then navigate to > Page A1 Credentials for A type
if the user choses login type B then navigate to > Page B1 Credentials for B type

if Login is successful for page A1 navigate to > Page A2
if Login is successful for page B1 navigate to > Page B2


            Page A1 --- Login Successful ---> Page A2
          /
         /
        /
Page …
Run Code Online (Sandbox Code Playgroud)

xamarin maui

3
推荐指数
1
解决办法
4656
查看次数

MAUI.NET 在按下后退按钮时显示弹出窗口

我试图在用户点击 MAUI 应用程序中的后退按钮时显示一个弹出窗口。

我发现这很棘手,因为 DisplayAlert 是一个需要等待的异步方法,但 OnButtonPressed 的重写是同步的。

如果我尝试在单独的等待任务中发送警报,它将显示。但应用程序仍会导航离开,因为它没有等待它。

我看不到任何异步重写 OnButtonPressed 的方法。

理想情况下,我尝试做这样的事情:

protected override bool OnBackButtonPressed()
{
    var leave = await DisplayAlert("Leave lobby?", "Are you sure you want to leave the lobby?", "Yes", "No");

    if (leave)
    {
        await handleLeaveAsync();
        return base.OnBackButtonPressed();
    }
    else
    {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢!

c# maui

3
推荐指数
1
解决办法
6544
查看次数

如何在毛伊岛使用 DependencyProperty?

我正在尝试在毛伊岛使用依赖属性,但它似乎不适用于毛伊岛。它显示参考缺失错误。我该如何解决?相同的代码在 xamarin 和 uwp 中工作,但在毛伊岛它显示 DependencyProperty 关键字的引用错误。

以下是代码示例:

  public static CornerRadius GetCornerRadius(Button element)
    {
        return (CornerRadius)element.GetValue(CornerRadiusProperty);
    }

    public static readonly DependencyProperty CornerRadiusProperty =
        DependencyProperty.RegisterAttached(
            "CornerRadius",
            typeof(CornerRadius),
            typeof(ButtonHelperClass),
            new PropertyMetadata(new CornerRadius(5))
            );
Run Code Online (Sandbox Code Playgroud)

c# maui .net-6.0

3
推荐指数
1
解决办法
1907
查看次数

获取 MAUI android (net6-android) 库中当前的 Android 活动

我有一个 Xamarin.Forms (Android) 库,允许使用 NFC,代码如下:

public class MediaAccessReader : Java.Lang.Object, NfcAdapter.IReaderCallback
{
    public const string TypeName = "Nfc";
    private static NfcAdapter NfcAdapter { get; } = NfcAdapter.GetDefaultAdapter(Android.App.Application.Context);
    public string Name { get; set; }

    public void Initialize(MediaAddedEventHandler mediaAdded, MediaRemovedEventHandler mediaRemoved)
    {                        
        Name = "Nfc";
#if XAMARINANDROID
         var activity = Forms.Context as Activity;
         NfcAdapter?.EnableReaderMode(activity, this, NfcReaderFlags.NfcA | NfcReaderFlags.NfcB | NfcReaderFlags.NfcF | NfcReaderFlags.NfcV | NfcReaderFlags.SkipNdefCheck, Bundle.Empty);
#else
         var activity = ?????????????????;
         NfcAdapter?.EnableReaderMode(activity , this, NfcReaderFlags.NfcA | NfcReaderFlags.NfcB | NfcReaderFlags.NfcF | NfcReaderFlags.NfcV | …
Run Code Online (Sandbox Code Playgroud)

android-activity maui net6.0-android nfcadapter

3
推荐指数
1
解决办法
2387
查看次数

直接点击项目时 CollectionView SelectionChanged 方法不触发.NET MAUI

我正在 .net MAUI 中创建一个 CollectionView,其中我在数据模板内使用 Frame 控件。因此,当我直接点击该项目时,SelectionChanged 方法不会被触发,只有当我单击框架边框或其外部时才会触发。下面是示例代码和图片。这是 MAUI 中的错误还是我做错了什么?我在 Xamarin 中进行了相同的设置,并且运行没有任何问题。

\n

XAML

\n
 <CollectionView x:Name="scheduleItemsCollection" \n                                    SelectionChanged="scheduleItemsCollection_SelectionChanged"\n                                    SelectionMode="Single"\n                                  >\n                        <CollectionView.ItemsLayout>\n                            <GridItemsLayout Orientation="Vertical"\n                                     Span="2"\n                                     />\n                        </CollectionView.ItemsLayout>\n\n                        <CollectionView.ItemTemplate>\n                            <DataTemplate>\n\n                                <Grid Padding="5" RowSpacing="0">\n\n                                 <Frame CornerRadius="40" BorderColor="Gray"> \n                                        <StackLayout Spacing="0" BackgroundColor="White">\n                                            <Label  Text="{Binding bookingDayArabic}" />\n                                            <Label   Text="{Binding bookingDateD}" />\n                                            <StackLayout Orientation="Horizontal">\n                                              \n                                                <Label Text="{Binding slotsAvailable}" HorizontalOptions="CenterAndExpand" />\n                                                <Label Text="\xd8\xb9\xd8\xaf\xd8\xaf \xd8\xa7\xd9\x84\xd8\xb7\xd9\x84\xd8\xa8\xd8\xa7\xd8\xaa:"/>\n                                            </StackLayout>\n                                        </StackLayout>\n                             </Frame> \n                                </Grid>\n\n\n                            </DataTemplate>\n\n                        </CollectionView.ItemTemplate>\n\n                    </CollectionView>\n
Run Code Online (Sandbox Code Playgroud)\n

在此输入图像描述

\n

collectionview selectionchanged maui

3
推荐指数
1
解决办法
2684
查看次数

定制 NET MAUI 启动画面

我正在尝试在.Net MAUI中制作一个包含渐变背景和动画徽标的启动屏幕。

我看过有关如何制作简单的飞溅的教程:

  <MauiSplashScreen Include="Resources\Images\splashscreen.svg" Color="#512BD4" />
Run Code Online (Sandbox Code Playgroud)

但是,我无法弄清楚如何在不使用完整的现成背景的情况下自定义启动画面,因为我不知道不同平台的完美尺寸是多少。

一些例子:

实施例1

动画示例

谢谢。

注意。

.net xamarin maui .net-maui

3
推荐指数
1
解决办法
7637
查看次数