xaml 相关问题

可扩展应用程序标记语言(XAML)是一种基于XML的声明式语言,用于在各种框架中初始化结构化值和对象。当问题是关于具有特定框架的XAML的使用时,还应该提供框架的标签,例如, [wpf](Windows Presentation Foundation),[silverlight],[windows-phone],[windows-store-apps](Windows 8商店应用),[win-universal-app],[xamarin.forms]或[工作流程 - 基础]

如何使用后面的c#代码将列宽设置为WPF中文本/*/Auto的任一大小?

我想在代码后面创建数据网格,并将其添加到其他区域(例如,每个 tabitem 都有一个数据网格)。然而,每次我不断得到列的长度......

回答 1 投票 0

获取 List.Count 绑定到 DataGridView 的集合的子属性中的项目数

我的 XAML 页面中有一个 DevExpress DataGridView,其内容绑定到 Document 对象的集合。每个对象都包含一个项目列表。我想显示...

回答 1 投票 0

.NET Maui - 如果存在未保存的数据或条件,则阻止选项卡导航

如果 .NET Maui 中不满足特定条件,如何阻止我的应用程序切换选项卡? 我需要在选项卡导航到单击的选项卡之前验证条件。如果不满足条件,...

回答 1 投票 0

如何克服 .NET MAUI 中路径和画布绘图的模糊性?

我目前正在开发一个使用 .NET MAUI 的项目,并利用 Path 和 Canvas 组件来绘制各种形状和波浪线。但是,当我扫描时遇到模糊问题...

回答 1 投票 0

获取父控件模板WPF的属性

我希望 POPUP 内的 ComboBox 项目采用 ToggleButton 的高度和宽度,对于宽度来说很好,因为我可以将它绑定在 POPUP 上,但高度适用于每个 ComboBox 项目,这是一个单独的...

回答 1 投票 0

MAUI (MVVM):在选择器选择更改时调用视图模型中的命令

在.NET MAUI中,有一个控件“Picker”,它似乎没有用于在页面视图模型中调用命令的选项。按钮有一个“命令”,允许您选择...

回答 1 投票 0

绑定到数组元素

我正在尝试将 TextBlock 绑定到 ObservableCollection 中的特定元素。 这就是我现在所做的: 私有 ObservableCollection arr = new ObservableCollection...

回答 4 投票 0

重新定义控件模板时可以使用内置的静态资源吗

在WPF中,如果我想重新定义控件样式,在我制作特殊按钮的示例中,我知道我可以使用Visual Studio提取模板的副本供我使用。 然而,当视觉研究...

回答 1 投票 0

ContentView 属性和 ViewModel 的对象属性之间的绑定错误 - 为什么?

我正在 MVVM 中开发 MAUI 应用程序,我遇到了绑定错误(当运行应用程序并导航到有问题的页面时),我不明白。这是我正在做的事情: 在...

回答 1 投票 0

列表视图中无法显示图片

我在列表视图中显示图片时遇到问题。我有一个 url 数组,我必须从中下载图片,但出于测试目的,我尝试使用我的

回答 1 投票 0

Xaml 绑定中的 Switch (Select) 语句?

有没有办法在 XAML 中创建条件绑定? 例子: ...

回答 6 投票 0

如何在毛伊岛堆叠两个图像按钮

我有一个 dotnet Maui 应用程序,在我的一个表单中,我希望最终用户选择他们想要的图片作为背景图像之一。为了表明他们已经选择了一位ima...

回答 1 投票 0

将 CommunityToolkit 中的 BitmapIcon 标记扩展与 ThemeResource 结合使用

我在 WinUI 3 中有以下 XAML 代码: 我在 WinUI 3 中有这个 XAML 代码: <ctc:SettingsCard Header="Directory"> <ctc:SettingsCard.HeaderIcon> <BitmapIcon ShowAsMonochrome="False" UriSource="{ThemeResource DirectoryIcon}"/> </ctc:SettingsCard.HeaderIcon> </ctc:SettingsCard> <ResourceDictionary.ThemeDictionaries> <ResourceDictionary x:Key="Light"> <x:String x:Key="DirectoryIcon">/Assets/DirectoryIconLight.png</x:String> </ResourceDictionary> <ResourceDictionary x:Key="Dark"> <x:String x:Key="DirectoryIcon">/Assets/DirectoryIconDark.png</x:String> </ResourceDictionary> </ResourceDictionary.ThemeDictionaries> 上面的代码工作正常。 CommunityToolkit.WinUI 中有一个 BitmapIconExtension,其示例如下: <MenuFlyout xmlns:ui="using:CommunityToolkit.WinUI"> <!--Before--> <MenuFlyoutItem Text="Click me!"> <MenuFlyoutItem.Icon> <BitmapIcon Source="/Assets/myicon.png"/> </MenuFlyoutItem.Icon> </MenuFlyoutItem> <!--After--> <MenuFlyoutItem Text="No, click me!" Icon="{ui:BitmapIcon Source=/Assets/myicon.png}" /> </MenuFlyout> 所以,我应该能够做到这一点: <ctc:SettingsCard Header="Directory" HeaderIcon="{ui:BitmapIcon Source={ThemeResource DirectoryIcon},ShowAsMonochrome=False}"/> 但是这段代码不起作用。我收到此错误: Microsoft.UI.Xaml.Markup.XamlParseException: 'The text associated with this error code could not be found. Failed to assign to property 'CommunityToolkit.WinUI.BitmapIconExtension.Source'. [Line: 142 Position: 39]' 是否可以将此标记扩展与 ResourceDictionary 中的静态/主题资源一起使用? 我试图让它实现你想要实现的目标,但这似乎是不可能的。 现在让我建议一个带有 ValueConverter 的替代方案: public class StringToBitmapIconConverter : IValueConverter { public object? Convert(object value, Type targetType, object parameter, string language) { if (value is not string path) { return null; } if (path.StartsWith("ms-appx:") is false) { path = $"ms-appx://{path}"; } return new BitmapIcon { UriSource = new Uri(path), }; } public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); } 然后像这样使用它: <ctc:SettingsCard Header="Directory" HeaderIcon="{Binding Source={ThemeResource DirectoryIcon}, Converter={StaticResource StringToBitmapIconConverter}}" />

回答 1 投票 0

为MAUI类库全局设置资源字典

使用“MAUI 应用程序”,我们在 App.xaml 文件中使用以下代码来全局使用整个应用程序的样式: 使用“MAUI 应用程序”,我们在 App.xaml 文件中使用以下代码来全局使用整个应用程序的样式: <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Resources/Styles/Colors.xaml" /> <ResourceDictionary Source="Resources/Styles/Styles.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> 有没有办法在“MAUI 类库”项目中使用样式并将其应用到所有 XAML 文件? 好吧,假设我们的 MAUI 类库提供了三种自定义标签类型和一个扩展按钮。 如果我们使用 .NET MAUI 资源字典 (XAML) 模板将“Resources.xaml”添加为新项目,我们可以添加一些值: <?xml version="1.0" encoding="utf-8" ?> <ResourceDictionary xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Library" x:Class="class_lib_with_static_resource_dict.Resources"> <x:String x:Key="DefaultText">My Text</x:String> <Style x:Key="BaseStyleEx" TargetType="local:LabelEx" > <Setter Property="HeightRequest" Value="100" /> <Setter Property="VerticalTextAlignment" Value="Center" /> <Setter Property="HorizontalTextAlignment" Value="Center" /> </Style> <Style TargetType="local:LabelEx" BasedOn="{StaticResource BaseStyleEx}"> <Setter Property="BackgroundColor" Value="WhiteSmoke" /> </Style> <Style TargetType="local:RedLabel" BasedOn="{StaticResource BaseStyleEx}"> <Setter Property="BackgroundColor" Value="LightSalmon" /> </Style> <Style TargetType="local:GreenLabel" BasedOn="{StaticResource BaseStyleEx}"> <Setter Property="BackgroundColor" Value="LightGreen" /> </Style> </ResourceDictionary> 链接 由于该类库不包含在公共 Application 类中,因此为了链接它,请在 xaml 中为任何想要使用它的类进行引用。 标签Ex <?xml version="1.0" encoding="utf-8" ?> <Label xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Library.LabelEx" HeightRequest="50" WidthRequest="150" Text="{StaticResource DefaultText}"> <Label.Resources> <ResourceDictionary Source="Resources.xaml"/> </Label.Resources> </Label> 在这种情况下,由于 RedLabel 和 GreenLabel 继承 LabelEx 这个单一引用就足够了。 按钮Ex <?xml version="1.0" encoding="utf-8" ?> <Button xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Library.ButtonEx" Text="{StaticResource DefaultText}"> <Button.Resources> <ResourceDictionary Source="Resources.xaml"/> </Button.Resources> </Button> 外部应用程序 现在修改默认的 Maui 应用程序以使用类库。 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:library="clr-namespace:Library;assembly=Library" x:Class="Client.MainPage"> <ScrollView> <VerticalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Image Source="dotnet_bot.png" SemanticProperties.Description="Cute dot net bot waving hi to you!" HeightRequest="200" HorizontalOptions="Center" /> <library:LabelEx SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Welcome to dot net Multi platform App U I" FontSize="18" /> <library:RedLabel SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Welcome to dot net Multi platform App U I" FontSize="18" /> <library:GreenLabel SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Welcome to dot net Multi platform App U I" FontSize="18" /> <library:ButtonEx x:Name="CounterBtn" SemanticProperties.Hint="Counts the number of times you click" Clicked="OnCounterClicked" HorizontalOptions="Center" /> </VerticalStackLayout> </ScrollView> </ContentPage>

回答 1 投票 0

带有 navigationargs 的 MAUI GoToAsync() 不起作用

我制作了一个 MAUI Shell 应用程序,其中包含 3 个带 TabBar 的可导航内容页面。 在主页中,用户输入许多内容,然后单击按钮。 当用户单击时,我想导航到 ListPage w...

回答 1 投票 0

如何将NotifyDataErrorInfo传递到自定义TextBox用户控件?

目标 我正在练习如何使用绑定到 Text 属性的不同类型的 TextBox。 有很多线程讨论这个问题。但是,我缺少一些步骤,并且会

回答 1 投票 0

是否可以在网格上添加边框

这是我的练习列表,我想在它们之间添加边框,这样客户就不会混淆哪个练习是设备。 我的代码如下。 这是我的练习列表,我想在它们之间添加边框,这样客户就不会混淆哪个练习是设备。 我的代码如下。 <StackLayout> <CollectionView ItemsSource="{Binding AllExerciseTypes}" SelectionMode="Single" BackgroundColor="{StaticResource TheBackgroundColor}" > <CollectionView.ItemTemplate> <DataTemplate x:DataType="Models:ExerciseType"> <Grid Padding="10" ColumnDefinitions="Auto,*" RowDefinitions="Auto, *"> <Label FontSize="Body" Grid.Column="1" FontAttributes="Bold" Text="{Binding Name}" /> <Label Grid.Row="1" Grid.Column="1" FontAttributes="Italic" Text="{Binding TargetedMuscle}" /> <Label Text= "{Binding Equipment}" FontAttributes="Italic" HorizontalTextAlignment="End" Grid.Column="2" Grid.Row="1"/> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </StackLayout> </ContentPage> 我尝试制作一个框架,其中有网格,但不知道如何做 使用边框来执行此操作,您还可以配置边框 <Border Stroke="#C49B33" StrokeThickness="4" StrokeShape="RoundRectangle 40,0,0,40" Background="#2B0B98"> <Grid/> </Border 有关边框的详细信息可以在这里找到:https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/border?view=net-maui-8.0 此外,如果您不希望出现意外行为,请不要使用 Frame。 我用框架固定了它 <CollectionView.ItemTemplate> <DataTemplate x:DataType="Models:ExerciseType"> <Frame Padding="0.3" BorderColor="#AC94C9"> <Grid BackgroundColor="#000000" Padding="15" ColumnDefinitions="Auto,*" RowDefinitions="Auto, *"> <Label FontSize="Body" Grid.Column="1" FontAttributes="Bold" Text="{Binding Name}" /> <Label Grid.Row="1" Grid.Column="1" FontAttributes="Italic" Text="{Binding TargetedMuscle}" /> <Label Text= "{Binding Equipment}" FontAttributes="Italic" HorizontalTextAlignment="End" Grid.Column="2" Grid.Row="1"/> </Grid> </Frame> </DataTemplate> </CollectionView.ItemTemplate>

回答 2 投票 0

如何在 WinUI 中从 DataTemplate 绑定到 xaml 根对象的成员?

我尝试绑定到 DataTemplate 中我的页面的成员。 据此,应该可以将 Page 转换为我的自定义类型。 https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/x-bind-markup-

回答 1 投票 0

如何在网格视图中使用键盘(例如使用选项卡)关注 XAML WPF 中的 TextBlock?

我有一个文本块,它有一个带有转换器的绑定路径,但我无法使用选项卡按钮操作它。 Textblock 有一个 Onclick 属性,可以打开另一个页面。我想打开那个屏幕...

回答 1 投票 0

无法从资源/图像目录.NET MAUI(MAC 上的 VS)在 iPhone 模拟器上加载图像

我最近开始学习 .NET MAUI,所以如果问题显得很基本,请接受我的歉意。 这是 AppShell.xaml: 我最近开始学习 .NET MAUI,所以如果问题显得很基础,请接受我的歉意。 这是AppShell.xaml: <?xml version="1.0" encoding="UTF-8" ?> <Shell x:Class="Walmo_e_wallet_u.AppShell" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Walmo_e_wallet_u" xmlns:pages="clr-namespace:Walmo_e_wallet_u.Pages" Shell.FlyoutBehavior="Disabled"> <TabBar> <Tab Title="Home"> <ShellContent ContentTemplate="{DataTemplate pages:HomePage}" /> </Tab> <Tab Title="Chart"> <ShellContent ContentTemplate="{DataTemplate pages:ChartPage}" /> </Tab> <Tab Title="QR"> <ShellContent ContentTemplate="{DataTemplate pages:QrPage}" /> </Tab> <Tab Title="Notification"> <ShellContent ContentTemplate="{DataTemplate pages:NotificationPage}" /> </Tab> <Tab Title="Wallet"> <ShellContent ContentTemplate="{DataTemplate pages:WalletPage}" /> </Tab> </TabBar> </Shell> 这些是我拖放到图像文件夹中的图像: 现在我尝试简单地将它们加载为选项卡图标: <TabBar> <Tab Title="Home" Icon="home.png"> <ShellContent ContentTemplate="{DataTemplate pages:HomePage}" /> </Tab> <Tab Title="Chart" Icon="chart.png"> <ShellContent ContentTemplate="{DataTemplate pages:ChartPage}" /> </Tab> <Tab Title="QR" Icon="qr.png"> <ShellContent ContentTemplate="{DataTemplate pages:QrPage}" /> </Tab> <Tab Title="Notification" Icon="notification.png"> <ShellContent ContentTemplate="{DataTemplate pages:NotificationPage}" /> </Tab> <Tab Title="Wallet" Icon="wallet.png"> <ShellContent ContentTemplate="{DataTemplate pages:WalletPage}" /> </Tab> </TabBar> 我已将图像放入图像文件夹中,但是当我构建模拟器时,屏幕变黑,并且仍然卡住,没有错误消息。如果我从选项卡栏代码中删除图像,则应用程序加载成功。我在这里缺少什么? 我找到了缺失的部分。我必须选择所有图像作为 MauiImage。为此: 选择一张图像,右键单击,然后从上下文菜单中选择“构建操作”。从列表中选择 MauiImage。 对项目中的所有图像文件重复此过程。 构建并运行项目 通过将“构建操作”设置为 MauiImage,可以确保 .NET MAUI 正确处理图像。

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.