xaml 相关问题

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

按下 Enter 键时绑定文本框

TextBox 上的默认数据绑定是 TwoWay,仅当 TextBox 失去焦点时才会将文本提交到属性。 当我按下 En...时,是否有任何简单的 XAML 方法可以使数据绑定发生?

回答 13 投票 0

WPF CommandBindings、ViewModel 和 UserControl

我对 WPF 还很陌生,所以最好描述一下其意图: 我的主窗口内有多个用户控件。每个用户控件都有自己的按钮,我想将其绑定到

回答 1 投票 0

RoatedEvent“该成员无法识别或无法访问”

我不想使用由输入设备生成的事件,而是想使用一个自定义事件,该事件将在代码隐藏中以编程方式引发,作为我的 xaml 中的 EventTrigger。 这应该是可笑的...

回答 3 投票 0

如何将 WPF/XAML GridRow 的高度设置为 Auto,但仍将其限制为 Grid 的最大可用高度?

我有一个 GroupBox(包含一个 ListBox)和一个 Expander,每个都在网格内各自的行中: ...

回答 3 投票 0

如何在 WPF 中创建一个 2x2 网格,当元素改变可见性时调整大小

我正在尝试在 WPF 中创建一个包含两列和两行的网格。我希望网格以一种特殊的方式调整大小,具体取决于哪些单元格可见,我制作了一些插图以更好地表达...

回答 1 投票 0

如何将 ControlTemplate 内的控件的属性绑定到父 ContentView 的属性?

我创建了一个自定义控件,它可以有不同的演示文稿。我为此使用 ContentView 和 ControlTemplate。 现在 ContentView 确实有一些可绑定的属性,但它没有绑定......

回答 1 投票 0

如何绑定maui命令参数?

Visual Studio 2022 17.8.5,.NET8 我有 2 页。 第一个视图: Visual Studio 2022 17.8.5,.NET8 我有 2 页。 第一眼: <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:material="http://schemas.enisn-projects.io/dotnet/maui/uraniumui/material" x:Class="MyApp.Views.ItemsPage" Title="Items" x:Name="ThisItemsPage"> <StackLayout> <material:TreeView ItemsSource="{Binding Items}" SelectionMode="Single" SelectedItem="{Binding SelectedItem}"> <material:TreeView.ItemTemplate> <DataTemplate> <HorizontalStackLayout> <Label ... /> <Label ... /> <FlyoutBase.ContextFlyout> <MenuFlyout> <MenuFlyoutItem Text="Details" Command="{Binding DetailsCommand}" BindingContext="{Binding Path=BindingContext, Source={x:Reference ThisItemsPage}}" CommandParameter="{Binding Source={RelativeSource Self}, Path=Parent.BindingContext}" /> <MenuFlyoutItem Text="Delete" Command="{Binding DeleteCommand}" BindingContext="{Binding Path=BindingContext, Source={x:Reference ThisItemsPage}}" CommandParameter="{Binding Source={RelativeSource Self}, Path=Parent.BindingContext}" /> </MenuFlyout> </FlyoutBase.ContextFlyout> </HorizontalStackLayout> </DataTemplate> </material:TreeView.ItemTemplate> </material:TreeView> <!-- other elements --> </StackLayout> </ContentPage> CS课: public partial class ItemsPage : ContentPage { private ItemsViewModel Context; public ItemsPage(ItemsViewModel viewModel) { InitializeComponent(); Context = viewModel; BindingContext = Context; } // ... } 和 ItemsViewModel: public partial class ItemsViewModel : ObservableObject { [ObservableProperty] private Item? _selectedItem; [ObservableProperty] private ObservableCollection<Item> _items = new(); [RelayCommand] public async Task Details(Item obj) { // Some logic here } [RelayCommand] public async Task Delete(Item obj) { // Some logic here } // ... } 第二个观点: <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:models="clr-namespace:SpendAdvisor.Models" xmlns:converters="clr-namespace:SpendAdvisor.Converters" x:Class="SpendAdvisor.Views.OtherItemsPage" x:Name="ThisOtherItemsPage" Title="OtherItems"> <StackLayout> <!-- other elements --> <ListView ItemsSource="{Binding OtherItems}" HasUnevenRows="True"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Border> <Grid RowDefinitions="Auto" ColumnDefinitions="100, *, 80"> <Label Grid.Column="0" ... /> <Label Grid.Column="1" ... /> <Label Grid.Column="2" ... /> <FlyoutBase.ContextFlyout> <MenuFlyout> <MenuFlyoutItem Text="Details" Command="{Binding DetailsCommand}" BindingContext="{Binding Path=BindingContext, Source={x:Reference ThisOtherItemsPage}}" CommandParameter="{Binding Source={RelativeSource Self}, Path=Parent.BindingContext}" /> <MenuFlyoutItem Text="Delete" Command="{Binding DeleteCommand}" BindingContext="{Binding Path=BindingContext, Source={x:Reference ThisOtherItemsPage}}" CommandParameter="{Binding Source={RelativeSource Self}, Path=Parent.BindingContext}" /> </MenuFlyout> </FlyoutBase.ContextFlyout> </Grid> </Border> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> <!-- other elements --> </StackLayout> </ContentPage> CS课: public partial class OtherItemsPage : ContentPage { private OtherItemsViewModel Context; public OtherItemsPage(OtherItemsViewModel viewModel) { InitializeComponent(); Context = viewModel; BindingContext = Context; } // ... } 和OtherItem视图模型: public partial class OtherItemsViewModel : ObservableObject { [ObservableProperty] public ObservableCollection<OtherItem> _otherItems = new (); [RelayCommand] public async Task Details(OtherItem obj) { // Some logic here } [RelayCommand] public async Task Delete(OtherItem obj) { // Some logic here } // ... } 我仅在第二页时遇到下一个异常(当我尝试打开它时): 参数“参数”(对象)不能是 Myapp.ViewModels.OtherItemsViewModel 类型,因为命令类型需要 Myapp.Models.OtherItem 类型的参数。 (参数‘参数’) 如果我将参数OtherItem obj更改为object obj,一切正常,并且对象类型为OtherItem。我无法理解它:它传递了正确的对象,但它期望它不应该是那种类型。看起来 CommandParameter 在页面初始化时不起作用,但在运行时起作用。但同时为什么它适用于第一页。 那么如何正确传递该参数呢?我可以保留对象参数并调用类似 var casted = obj as OtherItem 的内容,但我想要单一风格的命令。 当你仔细想想,例外是有道理的,你在这里试图做的是 CommandParameter="{Binding Source={RelativeSource Self}, Path=Parent.BindingContext}" 在您的命令参数中,传递父级的绑定上下文,但是您会看到父级的 BindingContext(即您的 ListView)是您的 ViewModel(即 OtherItemsViewModel),而不是您应该做的是将当前对象作为参数发送,这样做是相当的简单,您基本上在 ListView/CollectionView 的 ItemTemplate 中执行此操作 CommandParameter="{Binding .}" 随时回复查询

回答 1 投票 0

.NET MAUI:有没有办法动态调整标签文本大小?

我已经使用 WPF 有一段时间了,其中 Viewbox 元素用于使应用程序更改 Label 的 FontSize 属性以及窗口的尺寸。在 MAUI 中不再有 Viewbox。作为...

回答 1 投票 0

Datatrigger 上的旋转动画仅触发一次 WPF

我的窗口中显示了一条带有箭头的路径,他应根据属性“BarcodeScanne.MovementDirection”进行旋转,但是动画仅在值更改后播放,并且...

回答 1 投票 0

如何确定页面是在应用启动时打开还是在应用中间打开?

我正在编写一个 .NET Maui 应用程序,我有一个内容页面,当它在程序启动时打开并且用户单击“取消”按钮时,我希望整个应用程序关闭。 但是,如果相同

回答 1 投票 0

XAML Maui Flyout 菜单的 C# 等效项 [NavigationPage.HasNavigationBar] 是关键点

我被 XAML 的一个小细节困住了...如果您知道答案,请帮忙。 环境:dotnet 7 平台:毛伊岛 X 平台 我正在尝试在我的应用程序中创建一个与 Xaml 等效的 C# 集合...

回答 1 投票 0

如何导航到 MAUI shell?

我的应用程序有以下流程, 登录页面(内容页面) 主页(带选项卡的外壳) 交付页面(带选项卡的外壳) 这个想法是向用户展示一个登录页面,一旦登录,我就......

回答 1 投票 0

带有数据绑定的MAUI自定义视图

我很可能在这里遗漏了一些东西,或者没有真正理解 MVVM 和数据绑定的工作原理,如果我问了一个明显的问题,那么很抱歉。我和我的团队正在从 Xamarin 重写我们的应用程序......

回答 1 投票 0

回答 7 投票 0

如何在 C# 中使用 Border.BackgroundSizing/Border.BackgroundTransition 属性

我正在实验室工作,以便在我的按钮对象上制作一些动画。我希望能够以指定的过渡速率更改边框背景大小,以便其在

回答 1 投票 0

热重载在 Visual Studio 17.7.4 中不起作用

我有一个WPF项目,Visual Studio现在让我头疼了好几天。几天前,我将 Visual Studio 版本升级到 17.8.0(我不记得之前的版本是哪个了...

回答 1 投票 0

WinUI 3 DropDownButton 的 FlyOut 宽度 100%

我这里有一个简单的下拉菜单: 我这里有一个简单的下拉菜单: <DropDownButton Grid.Row="1" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" ToolTipService.ToolTip="Select" Margin="0,7,0,0"> <TextBlock FontSize="14" Text="List of items" /> <DropDownButton.Flyout> <MenuFlyout x:Name="SelectFlyout" Placement="BottomEdgeAlignedLeft"> <MenuFlyoutItem Text="Item 1" HorizontalAlignment="Stretch" /> <MenuFlyoutItem Text="Item 2" HorizontalAlignment="Stretch" /> <MenuFlyoutItem Text="Item 3" HorizontalAlignment="Stretch" /> </MenuFlyout> </DropDownButton.Flyout> </DropDownButton> 我设法将 DropDownButton 本身的宽度设置为其容器(网格,半屏幕宽)的 100%,但无法对其 Flyout 执行相同的操作。有什么办法可以做到吗? 尝试下一个: 为您的 DropDownButton 命名并订阅 MenuFlyout 的 Opened 活动: <DropDownButton x:Name="DropDownButtonControl" Grid.Row="1" Margin="0,7,0,0" Width="1000" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" ToolTipService.ToolTip="Select"> <TextBlock FontSize="14" Text="List of items" /> <DropDownButton.Flyout> <MenuFlyout x:Name="SelectFlyout" Opened="SelectFlyout_Opened" Placement="BottomEdgeAlignedLeft"> <MenuFlyoutItem HorizontalAlignment="Stretch" Text="Item 1" /> <MenuFlyoutItem HorizontalAlignment="Stretch" Text="Item 2" /> <MenuFlyoutItem HorizontalAlignment="Stretch" Text="Item 3" /> </MenuFlyout> </DropDownButton.Flyout> </DropDownButton> 然后在代码隐藏中设置每个元素的Width: private void SelectFlyout_Opened(object sender, object e) { if (VisualTreeHelper .GetOpenPopupsForXamlRoot(this.XamlRoot) .FirstOrDefault() is not { } popup || popup.Child is not MenuFlyoutPresenter menuFlyoutPresenter) { return; } double targetWidth = this.DropDownButtonControl.ActualWidth; menuFlyoutPresenter.MaxWidth = targetWidth; foreach (MenuFlyoutItem menuFlyoutItem in menuFlyoutPresenter .FindDescendants() .OfType<MenuFlyoutItem>()) { menuFlyoutItem.MinWidth = targetWidth; menuFlyoutItem.MaxWidth = targetWidth; } } 注意: 要使用FindDescendants扩展方法,您需要安装CommunityToolkit.WinUI.Extensions NuGet包。

回答 1 投票 0

如何在 C# 中使用 Border.BackgroundSizing/Border.BacgroundTransition 属性

我正在实验室工作,以便在我的按钮对象上制作一些动画。我希望能够以指定的过渡速率更改边框背景大小,以便其在

回答 1 投票 0

C# Avalonia UI“App.axaml:根元素丢失”,但存在有效的 XAML

我正在构建一个 Avalonia UI MVVM 应用程序,它可以在我的台式电脑(.NET 7.0、Ubuntu 22.04)上编译并运行良好。但是,当我将其克隆到笔记本电脑并尝试运行它时,出现以下错误: 错误 AVL...

回答 1 投票 0

MVVM、XAML、C# - DependencyProperty - ItemsControl 中的 ObservableCollection 无法识别 Property

我对 MVVM 和 c# 系统相当陌生,只是将其用作一个小小的业余爱好。在过去的三天里,我一直对以下问题感到绝望。 我有一个带有相应的自定义控件视图...

回答 2 投票 0

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