我正在通過創建 MVVM 應用程式來學習 .net Maui。我在 .net Maui 應用程式之外有一個 DataModel 庫,其中包含在 Azure 函式和本地應用程式之間傳遞的資料的資料模型。這樣,模型始終在應用程式之間保持同步,并且它們只需在代碼中更改/更新一次。
應用程式中有一個 DataModels 庫的專案參考集。
但是,雖然我可以在 C# 代碼中鏈接和訪問 DataModels 庫,但我似乎無法在 XAML 端鏈接它。
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LicenseApp.MainPage"
xmlns:viewmodel="clr-namespace:LicenseApp.ViewModels"
xmlns:dms="clr-namespace:TestApp.DataModels"
xmlns:dms2="clr-namespace:DataModels;assembly=DataModels"
x:DataType="viewmodel:MainViewModel">
我也試過:
xmlns:dms2="clr-命名空間:MyModels.DataModels;assembly=DataModels"
xmlns:dms 決議為應用程式中的本地 DataModels 檔案夾,該檔案夾確實有效。但是,我不希望此應用程式中的資料模型。
xmlns:dms2 給出錯誤:
Error XLS0419 Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'DataModels' that could not be found.
該庫沒有提供代碼提示。
對于它的作業原理,這是嘗試在此處呼叫庫的代碼:
<CollectionView Grid.Row="2" Grid.ColumnSpan="3" ItemsSource="{Binding Items}" SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="dms2:Customer">
DataModels 庫編譯為“DataModels.dll”。客戶資料模型如下所示:
namespace MyModels
{
public static class Customer
{
public int Id { get; set; }
public DateTime Created { get; }
public DateTime Updated { get; }
public string? CustomerName { get; set; }
public string? CustomerPhone { get; set; }
public string? CustomerEmail { get; set; }
public string? CustomerGuid { get; }
}
}
我究竟做錯了什么?這應該是可能的,不是嗎?
uj5u.com熱心網友回復:
我發現了問題...
在我的 DataModels 庫中,我有:
public static class Customer
{
....
}
這在我的 xaml 檔案中沒有解決,但它能夠在代碼中解決。
一旦我從宣告中洗掉“靜態”,代碼提示就會找到類和程式集。一切編譯好之后。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/533326.html
標籤:C#xml毛伊岛
上一篇:如何操作集合視圖項的資料或值?
