Что заставляет мой ContentView требовать Winrt? [закрыто]C#

Место общения программистов C#
Ответить
Anonymous
 Что заставляет мой ContentView требовать Winrt? [закрыто]

Сообщение Anonymous »

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

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

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;
}
}
}
И это файл проекта .csproj :



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>
Я использую Visual Studio 2022 Community v17.14.15 и .net 9. < /p>
Используются пакеты: < /p>
Microsoft.Maui.Controls 9.0.82
Microsoft.NET.ILLink.Tasks 9.09
< /code>
(только основные пакеты для .net maui) < /p>
Может ли кто -нибудь сказать мне, что приводит к тому, что этот элемент требует Winrt, когда включен в качестве ссылки на проект? (включая источник с использованием добавления в качестве ссылки работает нормально)


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

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

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

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

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

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