質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.33%
.NET MAUI

.NET MAUIは、「.NET Multi-platform App UI」の略。単一コードで複数のプラットフォームに対応するクロスプラットフォームフレームワークです。Xamarin.Formsの進化系とされており、XAMLやMVVM に加え、MVUもサポートされています。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

XAML

XAML(Extensible Application Markup Language)はWPF、Silverlight、Windows PhoneそしてWindows Store appsでユーザーインターフェースを定義するために使われるXML言語です。

Q&A

解決済

1回答

234閲覧

Mauiの警告を消したい

RC46

総合スコア11

.NET MAUI

.NET MAUIは、「.NET Multi-platform App UI」の略。単一コードで複数のプラットフォームに対応するクロスプラットフォームフレームワークです。Xamarin.Formsの進化系とされており、XAMLやMVVM に加え、MVUもサポートされています。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

XAML

XAML(Extensible Application Markup Language)はWPF、Silverlight、Windows PhoneそしてWindows Store appsでユーザーインターフェースを定義するために使われるXML言語です。

2グッド

0クリップ

投稿2025/01/25 03:03

編集2025/01/25 07:13

実現したいこと

Mauiでxamlを記述している
BindingContext DataType関連の警告を消したい

前提

VisualstudioでMauiを使いC#でMVVM方式でアプリの開発をしている
大方、エラーも無くなり、稼働はできているものの、警告が消せないものがあり解決したい

BindingContext DataType関連だと思うが以下の警告がでる

発生している問題・警告メッセージ

Binding: Property "TestTapCommand" not found on "InspectApp.ViewModels.InspectItems".

発生しているXAMLバインドエラ―

Mismatch between the specified x:DataType (InspectApp.ViewModels.InspectItems) and the current binding context (Microsoft.Maui.Controls.RelativeBindingSource).

該当のソースコード

xaml

1<?xml version="1.0" encoding="utf-8" ?> 2<ContentPage 3 x:Class="SpecifyInspectApp.Views.UserCheckPage" 4 xmlns="http://schemas.microsoft.com/dotnet/2021/maui" 5 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 6 xmlns:local="clr-namespace:SpecifyInspectApp.ViewModels" 7 xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" 8 x:Name="MyPage" 9 x:DataType="local:UserCheckPageModel"> 10 11 <ContentPage.BindingContext> 12 <local:UserCheckPageModel /> 13 </ContentPage.BindingContext> 14 15 <ContentPage.Behaviors> 16 <toolkit:EventToCommandBehavior Command="{Binding NavigatedToCommand}" EventName="NavigatedTo" /> 17 <toolkit:EventToCommandBehavior Command="{Binding NavigatedFromCommand}" EventName="NavigatedFrom" /> 18 </ContentPage.Behaviors> 19 20 <ContentPage.Resources> 21 <ResourceDictionary> 22 ***省略*** 23 </ResourceDictionary> 24 </ContentPage.Resources> 25 26 <Grid> 27 <Grid RowDefinitions="Auto,Auto,Auto,*"> 28 ***省略--- 29 <Border 30 Grid.Row="3" 31 Padding="3" 32 Stroke="Navy" 33 StrokeThickness="2"> 34 <Grid> 35 <CollectionView 36 x:Name="collectionView" 37 EmptyView="No Data" 38 ItemsSource="{Binding DisplayList}" 39 ItemsUpdatingScrollMode="KeepScrollOffset" 40 SelectionMode="Single"> 41 <CollectionView.ItemTemplate> 42 <DataTemplate x:DataType="local:InspectItems"> 43 <Grid RowDefinitions="Auto,3"> 44 <Grid Grid.Row="0" ColumnDefinitions="190,80,90,80,150,*"> 45 <!-- 各セルを定義します --> 46 <Label 47 Grid.Column="0" 48 Style="{StaticResource ResultDataStyle}" 49 Text="{Binding PartNo}" /> 50 <Label 51 Grid.Column="1" 52 HorizontalTextAlignment="End" 53 Style="{StaticResource ResultDataStyle}" 54 Text="{Binding Qty}" /> 55 <Label 56 Grid.Column="2" 57 HorizontalTextAlignment="Center" 58 Style="{StaticResource ResultDataStyle}" 59 Text="{Binding ShipC}" /> 60 <Label 61 Grid.Column="3" 62 HorizontalTextAlignment="Center" 63 Style="{StaticResource ResultDataStyle}" 64 Text="{Binding ShipDate}" /> 65 <Label 66 Grid.Column="4" 67 Style="{StaticResource ResultDataStyle}" 68 Text="{Binding Slip}" /> 69 <Label 70 Grid.Column="5" 71 Style="{StaticResource ResultDataStyle}" 72 Text="{Binding DlvNo}" /> 73 <!-- 他の列も追加します --> 74 <Grid.GestureRecognizers> 75 <TapGestureRecognizer 76 Command="{Binding Source={RelativeSource AncestorType={x:Type local:UserCheckPageModel}}, Path=TestTapCommand}" 77 CommandParameter="{Binding .}" 78 NumberOfTapsRequired="2" /> 79 </Grid.GestureRecognizers> 80 </Grid> 81 <BoxView 82 Grid.Row="1" 83 BackgroundColor="Navy" 84 HeightRequest="1" 85 VerticalOptions="Center" /> 86 </Grid> 87 </DataTemplate> 88 </CollectionView.ItemTemplate> 89 </CollectionView> 90 </Grid> 91 </Border> 92 </Grid> 93 94 </Grid> 95</ContentPage>

C#

1namespace InspectApp.ViewModels 2{ 3 public partial class UserCheckPageModel : ObservableObject, IDisposable 4 { 5 /// <summary> 6 /// 表示用デ-タ 7 /// </summary> 8 public ObservableCollection<InspectItems> DisplayList { get; set; } = []; 9 10 } 11 12 public class InspectItems 13 { 14 public string ShipDate { get; set; } = "1/1"; 15 public string PartNo { get; set; } = "XZXZY-AAAA"; 16 public string Qty { get; set; } = "1"; 17 public string ShipC { get; set; } = "TOKYO"; 18 public string DlvNo { get; set; } = "372451_FFF"; 19 public string Slip { get; set; } = "372451"; 20 } 21} 22

試したこと

CollectionViewで対象のセルをダブルタップ・クリックしてデータを取得するコマンドを作りたい
<DataTemplate x:DataType="local:InspectItems">
で再度宣言しているのでこれが原因とは思っている
しかし
<DataTemplate x:DataType="local:InspectItems">
を宣言しないとBinding PartNoなどが全く反映されない上、別の警告が大量に発生する

ネット上にも有益な情報はなく
Muaiではこの警告は仕方がないものなのか、ほかに消す方法があるのか知りたい

※一応、データの表示、ダブルタップでの動作は検証成功している

TN8001😄を押しています
TN8001👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

RC46

2025/01/25 07:15

ありがとうございます .NET が頭に必要だったのですね 修正しました
guest

回答1

0

ベストアンサー

BindingContext DataType関連だと思うが以下の警告がでる

こちらの手元では再現できませんでした(こちらの環境的な問題かもしれません)

そのかわりXC0025の警告が出ていました。
コンパイル済みのバインディング - .NET MAUI | Microsoft Learn

該当のソースコード
※一応、データの表示、ダブルタップでの動作は検証成功している

肝心のTestTapCommandの記述がありませんが、UserCheckPageModelにあると考えていいわけですね?


おそらくどちらも同種の問題で、「バインドでSourceを使うときはx:DataTypeも書きましょう」ということなんだろうと思います。
Binding context type check fails for relative binding sources · Issue #25608 · dotnet/maui
Mismatch between the specified x:DataType and the current binding context. · Issue #26086 · dotnet/maui

xml

1<TapGestureRecognizer 2 Command="{Binding x:DataType=local:UserCheckPageModel, Source={RelativeSource AncestorType={x:Type local:UserCheckPageModel}}, Path=TestTapCommand}" 3 CommandParameter="{Binding .}" 4 NumberOfTapsRequired="2" />

ネット上にも有益な情報はなく

エラーコードや(プロジェクト固有でない部分の)エラーメッセージでggってください^^
the current binding context (Microsoft.Maui.Controls.RelativeBindingSource). - Google 検索

投稿2025/01/25 06:21

TN8001

総合スコア9937

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

RC46

2025/01/25 07:32

Command="{Binding x:DataType=local:UserCheckPageModel, Source={RelativeSource AncestorType={x:Type local:UserCheckPageModel}}, Path=TestTapCommand}" x:DataType="local:InspectItems"も含めて x:DataType=local:UserCheckPageModel あちこちDataTypeの位置を変えてみたりしていたんですが、ここの箇所には多分入れてません 唯一解決できなかったXC0045の警告がすべて消えました 大変助かりました ありがとうございます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.33%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問