可扩展应用程序标记语言(XAML)是一种基于XML的声明式语言,用于在各种框架中初始化结构化值和对象。当问题是关于具有特定框架的XAML的使用时,还应该提供框架的标签,例如, [wpf](Windows Presentation Foundation),[silverlight],[windows-phone],[windows-store-apps](Windows 8商店应用),[win-universal-app],[xamarin.forms]或[工作流程 - 基础]
我正在尝试对数据网格中的数据进行排序,但是当我单击与转换器绑定的列的标题时,没有任何反应。我使用MVVM模式。下面附有示例。在示例中...
最近,即使启用了云母背景,我的 WinUI 3 应用程序的标题栏也是白色的。如何解决此问题,以便云母也扩展到标题栏? 最近,即使启用了云母背景,我的 WinUI 3 应用程序的标题栏也是白色的。我该如何解决这个问题,以便云母也延伸到标题栏? <Window.SystemBackdrop> <MicaBackdrop/> </Window.SystemBackdrop> 这种情况并不总是发生,当我输入上面的代码时,标题栏是云母背景的一部分,而不是白色。 您可以使用 ExtendsContentIntoTitleBar 属性。 public sealed partial class MainWindow : Window { public MainWindow() { InitializeComponent(); ExtendsContentIntoTitleBar = true; } }
我想知道如何使用 Visual Studio 提取(获取副本)给定控件的默认模板。我知道这可以通过 Expression Blend 来完成(右键单击控件,“编辑模板”->...
我有一个对象 DataSet,它有一个 name 属性和一个 ID 属性。我的视图模型中有一个数据集列表,它应该是 DataGrid Combobox 列的项目源。我已经定义了双...
所以我在 ObjA 类上的“GroupColour”属性上遇到了一些 ATM 绑定问题。我还有一个 CurrentState 变量,它根据其值返回一个 Brush(这是在转换器中完成的......
我还是 wpf 的新手,所以请耐心等待。 我有一个 GroupBox 来处理我的日志记录。它的内部是用于滚动的 ScrollViewer 和用于包含日志记录的 TextBox。我想要的是在某些
我创建了自己的控件 MenuButton,如下图所示: 因此,当我单击按钮时菜单项会出现,而当焦点丢失时菜单项会隐藏。处理菜单上的点击
我正在开发一个Windows游戏前端,它显示所有已安装的Steam、Epic和GOG游戏,以及安装在C盘上的游戏。但是,当我使用蓝牙控制器启动游戏时
WPF 中带有 TextBox 的 TreeViewItem:输入特殊字符
我需要编辑一些层次结构,我使用 TreeView 和 TextBoxes 简短的例子 &...
由于 xceed wpf 工具包对我不起作用,我尝试使用 C# 和 WPF 创建自定义多选组合框,方法是使用复选框填充组合框并设置其宽度属性,以便...
在 XAML 通用 Windows 平台中向 {x:Bind} 添加附加字符串
我是 XAML 新手。我想向 x:bind 添加额外的字符串 我已经尝试过 我是 XAML 新手。我想向 x:bind 添加额外的字符串 我已经尝试过了 <AppBarToggleButton Icon="Phone" Label="E-Mail To {x:Bind e_mail}" /> <AppBarToggleButton Icon="Phone" Label="{"E-Mail To" + x:Bind e_mail}" /> 我想收到“电子邮件至 [email protected]” 但没有成功。感谢您的帮助。 为此创建一个转换器: public sealed class StringFormatConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { if (value == null) return null; if (parameter == null) return value; return string.Format(parameter.ToString(), value); } public object ConvertBack(object value, Type targetType, object parameter, string language) { throw new NotImplementedException(); } } 将此添加到您的页面/控件/应用程序资源中: <converters:StringFormatConverter x:Key="StringFormatConverter" /> 然后像这样使用它: <TextBlock Text="{x:Bind e_mail}" Converter="{StaticResource StringFormatConverter}" ConverterParameter="E-Mail To {0}!" /> 您可以使用 Microsoft 的 内置转换器,而不是创建自己的 StringFormatConverter: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:converter="using:Microsoft.Toolkit.Uwp.UI.Converters" mc:Ignorable="d"> <converter:StringFormatConverter x:Key="StringFormatConverter"/> </ResourceDictionary> 还有一些其他有用的内置转换器,请查看: https://learn.microsoft.com/en-us/dotnet/api/microsoft.toolkit.uwp.ui.converters?view=win-comm-toolkit-dotnet-7.0 使用x:Bind功能: <AppBarToggleButton Icon="Email" Label="{x:Bind x:String.Format('E-Mail To {0}', e_mail)}"/>
我是 WPF 新手,我正在尝试创建一个包含一些嵌套内容的 UserControl。 我是 WPF 新手,我正在尝试创建一个包含一些嵌套内容的 UserControl。 <my:InformationBox Header="General Information" Width="280"> <StackPanel> <Label>Label1</Label> <Label>Label2</Label> </StackPanel> </my:InformationBox> 如你所见,我想在其中放入一个 StackPanel。当我阅读一些文章时,我应该将 ContentPresenter 添加到我的 UserControl 中,所以我这样做了,但我找不到应该绑定到它的 Content 属性的内容。 这是我的用户控制代码 <UserControl x:Class="ITMAN.InformationBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="280" Name="infoBox" Loaded="infoBox_Loaded"> <StackPanel Width="{Binding ElementName=infoBox, Path=Width}" HorizontalAlignment="Stretch"> <Label Content="{Binding ElementName=infoBox, Path=Header}" /> <Border BorderThickness="0,1,0,0" Padding="10 5" Margin="5 0 5 10" BorderBrush="#B4CEDE"> <StackPanel> <ContentPresenter Content="{Binding Content}" /> <Label Content="End" /> </StackPanel> </Border> </StackPanel> </UserControl> 我尝试了各种文章中的多种组合,但我找不到任何我想要实现的目标的工作示例。 另一位用户早些时候提出了类似的问题,但给出的答案对我没有帮助:有人有一个带有单个 ContentPresenter 的 UserControl 的简单示例吗? ContentPresenter 是一种神奇的控制。如果您不向其提供任何内容,它将自动将 Content、ContentTemplate 和 ContentTemplateSelector 属性(其中 TemplateBinding)设置为 TemplatedParent。这意味着,您不需要向其提供任何内容,只需 <ContentPresenter/> 在您的用户控件中,它应该自动使用您的用户控件中找到的相应属性。 另请记住,像 {Binding Content} 这样的绑定始终引用您的 DataContext,我猜这不是您想要的。 我通过将自定义样式应用于GroupBox解决了这个问题。我在ResourceDictionary中创建了Syle,如下所示 <Style x:Key="InformationBoxStyle" TargetType="GroupBox"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="GroupBox"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Label> <ContentPresenter Margin="4" ContentSource="Header" RecognizesAccessKey="True" /> </Label> <Border Grid.Row="1" BorderThickness="0,1,0,0" Padding="10 5" Margin="5 0 5 10" BorderBrush="#B4CEDE"> <StackPanel> <ContentPresenter /> </StackPanel> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> 并将这种风格应用到GroupBox <GroupBox Header="General Information" Width="280" Style="{StaticResource InformationBoxStyle}"> <StackPanel> <Label>Label1</Label> <Label>Label2</Label> </StackPanel> </GroupBox> 此代码按预期工作 您还可以参考这篇很棒的文章,其中展示了实现它的不同选项: http://www.codeproject.com/Articles/82464/How-to-Embed-Arbitrary-Content-in-a-WPF-Control 它还描述了为什么 ContentPresenter 在我的代码中不起作用。 您需要在 UserControl 代码后面创建依赖属性,例如 InnerContent。 public object InnerContent { get { return GetValue(InnerContentProperty); } set { SetValue(InnerContentProperty, value); } } public static readonly DependencyProperty InnerContentProperty = DependencyProperty.Register("InnerContent", typeof(object), typeof(ConfirmationControl), new PropertyMetadata(null)); 然后您需要绑定到该 UserControl 的 XAML 端的 InnerContent。 <ContentControl Content="{Binding InnerContent, ElementName=userControl}" /> 然后,当您使用它时,不要直接将内容放入 UserControl 中并覆盖现有内容,只需将其添加到 InnerContent 部分即可。 <UserControls:InformationBox> <UserControls:InformationBox.InnerContent> <TextBlock Text="I'm in the InnerContent" /> </UserControls:InformationBox.InnerContent> </UserControls:InformationBox> 否则使用模板或样式也同样好,但如果您想打包一个用户控件以供使用而不强迫任何人也引用样式或模板,这可能是您更好的选择之一。 如果您想像示例中那样使用它,您可以使用 ContentControl 或 UserControl 并像这样使用它: <UserControl x:Class="ITMAN.InformationBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="280" Name="infoBox" Loaded="infoBox_Loaded"> <UserControl.Template> <ControlTemplate TargetType="local:YourClassName"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Label> <ContentPresenter Margin="4" ContentSource="Header" RecognizesAccessKey="True" /> </Label> <Border Grid.Row="1" BorderThickness="0,1,0,0" Padding="10 5" Margin="5 0 5 10" BorderBrush="#B4CEDE"> <StackPanel> <ContentPresenter /> </StackPanel> </Border> </Grid> </ControlTemplate> </UserControl.Template> </UserControl> 这种方法不需要在其他地方设置样式。由于模板将与组件定义一起驻留,因此维护起来会更容易。 <local:InformationBox> <!--Your content goes here--> </local:InformationBox> 无论您在 InformationBox 组件中设置什么,都将在您放置标签的位置呈现。这也适用于 WinUI3
有谁知道有什么方法可以将简单的gif转换为xaml吗? 例如。一个可以查看图像并根据 gif / jpg / 位图创建椭圆、矩形和路径的工具?
我有一个 wpf 应用程序,在带触摸屏的 Windows IoT 中运行。 我有一些带有组合框的屏幕,允许用户按下它并选择一个项目并保存它。 组合框被放入
如何使用 AdvancedCollectionView 源更新 UWP ListView 中的项目
我使用 Windows Community Toolkit 中的 AdvanceCollectionView 作为 XAML ListView 的源,以允许排序和过滤。我在更新 ListView 时遇到问题。 要复制的是...
我正在为我的期末大学项目(论文)开发一个 WPF 应用程序。目标之一是能够动态更改 UI 的语言。我认为这样做不是一个好主意...
Visual Studio 2022 - XAML 设计器无法为 WinUI 项目打开
无法在 XAML 设计器中打开任何 .xaml 文件 - 每当我尝试使用 XAML 设计器打开 XAML 文件时,它都会使用文本编辑器打开 我尝试过的: 确保工具 > 选项 >...
您好,我需要在 WPF 应用程序中使用 MVVM 和实体框架在 DataGrid 中显示交付列表。每个交付都有一个指定的快递员,可以通过对话框编辑窗口进行更改。这一切
Xamarin:AbsoluteLayout 中的网格不填满屏幕
我有一个包含网格的绝对布局。从图中可以看出,absoluteLayout 正确地水平填充了屏幕。问题似乎是网格,它不是为整个