.NET MAUI, что заставляет мой ContentView, требуется WinRTC#

Место общения программистов C#
Ответить
Anonymous
 .NET MAUI, что заставляет мой ContentView, требуется WinRT

Сообщение Anonymous »

У меня есть представление C# Custom Content, которое я хочу включить в качестве ссылки на проект, а не использование Add As Link, но любое приложение, которое использует элемент управления в качестве эталона, не может построить из -за того, что WinRT не найден.
Вот контроль < /p>

Код: Выделить всё

namespace CustomTitleViewControl.Controls
{
public partial class CustomTitleViewControl : ContentView
{
public static readonly BindableProperty TitleTextProperty =
BindableProperty.Create(nameof(TitleText), typeof(string), typeof(CustomTitleViewControl), default(string));

public string TitleText
{
get => (string)GetValue(TitleTextProperty);
set => SetValue(TitleTextProperty, value);
}

public static readonly BindableProperty TitleColourProperty =
BindableProperty.Create(nameof(TitleColour), typeof(Color), typeof(CustomTitleViewControl), Colors.Transparent);
public Color TitleColour
{
get => (Color)GetValue(TitleColourProperty);
set => SetValue(TitleColourProperty, value);
}
public static readonly BindableProperty TitleFontSizeProperty =
BindableProperty.Create(nameof(TitleFontSize), typeof(double), typeof(CustomTitleViewControl), 32.0);

public double TitleFontSize
{
get => (double)GetValue(TitleFontSizeProperty);
set => SetValue(TitleFontSizeProperty, value);
}
public static readonly BindableProperty TitleAlignmentProperty =
BindableProperty.Create(nameof(TitleAlignment), typeof(TextAlignment), typeof(CustomTitleViewControl), TextAlignment.Center);
public TextAlignment TitleAlignment
{
get => (TextAlignment)GetValue(TitleAlignmentProperty);
set => SetValue(TitleAlignmentProperty, value);
}

public CustomTitleViewControl()
{
var label = new Label
{
VerticalTextAlignment = TextAlignment.Center,
};
label.SetBinding(Label.TextProperty, new Binding(nameof(TitleText), source: this, mode: BindingMode.OneWay));
label.SetBinding(Label.HorizontalTextAlignmentProperty, new Binding(nameof(TitleAlignment), source: this, mode: BindingMode.OneWay));
label.SetBinding(Label.FontSizeProperty, new Binding(nameof(TitleFontSize), source: this, mode: BindingMode.OneWay));
label.SetBinding(Label.BackgroundColorProperty, new Binding(nameof(TitleColour), source: this, mode: BindingMode.OneWay));
var outerGrid = new Grid { };
outerGrid.Children.Add(label);
Content = outerGrid;

// 🪄 Defer layout logic for Windows
if (DeviceInfo.Current.Idiom == DeviceIdiom.Desktop)
{
Dispatcher.Dispatch(() =>
{
var navPage = FindAncestorNavigationPage(this);
if (navPage?.CurrentPage != null)
{
outerGrid.WidthRequest = navPage.CurrentPage.Width;

navPage.CurrentPage.SizeChanged += (s, e) =>
{
outerGrid.WidthRequest = navPage.CurrentPage.Width;
};
}
});
}

outerGrid.InvalidateMeasure();
}
// Add this helper method inside the CustomTitleView class to resolve CS0103
private static NavigationPage? FindAncestorNavigationPage(Element? element)
{
while (element != null)
{
if (element is NavigationPage navPage)
return navPage;
element = element.Parent;
}
return null;
}
}
}
< /code>
и .csproj < /p>



net9.0-android;net9.0-ios;net9.0-maccatalyst
$(TargetFrameworks);net9.0-windows10.0.19041.0


true
true
enable
enable

15.0
15.0
21.0
10.0.17763.0
10.0.17763.0
6.5







< /code>
Я использую Virtual Studio Community 2022 Версия 17.14.15 и Dotnet 9. Пакеты < /p>
Microsoft.Maui.Controls 9.0.82
Microsoft.NET.ILLink.Tasks 9.09
(только основные пакеты для .net maui)
Кто -нибудь может сказать мне, что приводит к тому, что этот элемент управления требует Winrt, когда включен в качестве ссылки на проект (включая источник, используя Add As Link работает нормально).

Подробнее здесь: https://stackoverflow.com/questions/797 ... uire-winrt
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»