wpf 相关问题

Windows Presentation Foundation或WPF是用于在基于Windows的应用程序中呈现用户界面的子系统。

wpf RowDetailsTemplate 焦点

我目前有一个带有 rowdetailstemplate 的数据网格,其中包含另一个数据网格来显示父子关系。第二个网格有一列,其中包含一个按钮,单击该按钮时

回答 3 投票 0

如何设置SmallImageSource属性?

我是 wpf 的新手。现在我正在构建一个wpf项目。以下是我的 MainWindow.xaml 的部分内容: 我是 wpf 的新手。现在我正在构建一个wpf项目。以下是我的 MainWindow.xaml 的部分内容: <Ribbon.ApplicationMenu> <RibbonApplicationMenu SmallImageSource="Resources/Buttons/Export.png"> </RibbonApplicationMenu> </Ribbon.ApplicationMenu> 我可以在设计区域看到图标,但我们尝试运行它,我总是收到错误: can't locate source "Resources/Buttons/Export.png" 为什么? 解决了!必须设置 png 文件的属性!

回答 1 投票 0

自定义日期选择器:如何更改图标图像并单击代码隐藏上的文本框打开弹出窗口?

这是我的自定义日期选择器: 这是我的自定义日期选择器: <customcontrols:CustomDatePicker x:Name="DataCreazione" SelectedDate="{Binding DataCreazione, StringFormat={}{0:dd/MM/yyyy}}" controls:TextBoxHelper.Watermark="Data Creazione" Cursor="Hand" BorderThickness="0" SelectedDateFormat="Short" Margin="0,0,0,0" Grid.ColumnSpan="3" Grid.Row="1" /> 我将此模板应用于后面的代码: using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace Client.customcontrols { public class CustomDatePicker : DatePicker { public override void OnApplyTemplate() { base.OnApplyTemplate(); if (Template.FindName("PART_TextBox", this) is TextBox textbox) { textbox.IsReadOnly = true; textbox.Cursor = Cursors.Hand; textbox.PreviewMouseLeftButtonDown += PreviewMouseLeftButtonDown_Click; } if (Template.FindName("PART_Button", this) is Button button) { button.Visibility = Visibility.Hidden; } } private void PreviewMouseLeftButtonDown_Click(object sender, System.Windows.Input.MouseButtonEventArgs e) { IsDropDownOpen = true; } } } 我愿意: 而不是隐藏图标,我想更改它的图像(使用PackIconFontAwesome的CalendarAltSolid),大小16x16,边距0,0,8,0 单击文本框后,单击图标具有相同的行为(弹出窗口打开,在我选择日期之前保持打开状态);相反,使用 PreviewMouseLeftButtonDown,它似乎会保持弹出窗口打开,直到我按下鼠标左键单击,一旦其“向上”,弹出窗口就会消失 你能帮我解决这个问题吗? 您始终可以为Button定义自定义模板,例如: <customcontrols:CustomDatePicker x:Name="DataCreazione" SelectedDate="{Binding DataCreazione, StringFormat={}{0:dd/MM/yyyy}}" controls:TextBoxHelper.Watermark="Data Creazione" Cursor="Hand" BorderThickness="0" SelectedDateFormat="Short" Margin="0,0,0,0" Grid.ColumnSpan="3" Grid.Row="1" > <customcontrols:CustomDatePicker.Resources> <ControlTemplate x:Key="ButtonTemplate" TargetType="Button"> <Grid Background="Silver"> <iconPacks:PackIconControl Kind="{x:Static iconPacks:PackIconFontAwesomeKind.CalendarAltSolid}" Width="24" Height="24" /> </Grid> </ControlTemplate> </customcontrols:CustomDatePicker.Resources> </customcontrols:CustomDatePicker> if (Template.FindName("PART_Button", this) is Button button) { button.Template = FindResource("ButtonTemplate") as ControlTemplate; }

回答 1 投票 0

WPF WebBrowser 控件 LoadCompleted 事件未触发

我正在尝试使用 WPF WebBrowser Control 进行导航并在加载后获取文档。 导航事件已正确触发(但文档仍不完整) 但是 LoadCompleted 事件是不需要的...

回答 1 投票 0

使用FrameworkElement存储用户控件数据上下文

我成功解决了尝试从 DataGrid 控件内部访问视图模型属性时遇到的问题。另一个问题是我真的不明白为什么这是有效的。 所以基本上

回答 1 投票 0

在 C# WPF 应用程序中写入 csv 文件时出现问题

我需要将当前日期和时间以及程序的当前计数器值记录到 csv 文件中。它从一个启动计数器的按钮开始,该按钮运行一个执行 loggi 的方法...

回答 1 投票 0

WPF 中的 AddScoped 和 AddSingleton 有什么区别吗?

在 WPF 或任何不作为服务 Web 请求的 Web 应用程序运行的控制台应用程序的上下文中,如果我使用 Microsoft.Extensions.DependencyInjection,AddScoped 和 AddSingleton 方法如何

回答 1 投票 0

PC 到 Android 平板电脑串行 USB 通信

就像标题所述,我正在尝试从 PC 与 Android 平板电脑进行通信。我在平板电脑和 PC 之间连接了 USB-A 至 USB-C。平板电脑不会在 PC 的 D 中弹出为 COM 端口...

回答 1 投票 0

Powershell WPF GUI 作为计划任务不可见

我正在编写一个向用户显示 WPF GUI 的 PowerShell 脚本。任务计划程序应该每天在特定时间运行此脚本。 当我手动启动时,脚本运行良好,...

回答 3 投票 0

为什么 wpf itemlist 在 itemsource 更改后断开连接

我要制作可分页列表视图。 我几乎实现了除了索引显示之外的所有功能。 我将 listviewitem 作为多重绑定传递给转换器以显示索引。 但是listview显示索引t...

回答 1 投票 0

WPF 绑定相对于当前时间的日期时间

我正在寻找一种绑定日期时间但显示与当前时间的差异的方法。 这是 C# 代码: 公共部分类 MainWindow : 窗口 { 公共可观察集合<

回答 1 投票 0

Wpf gridview 选定的项目

我有 ListView 和 GridView 内部的 ListView 视图,并且指定了 ListView 项目源。我似乎没有找到怎么能。我得到 GridView 的 SelectedItem 或 SelectedItem 更改。 我有 ListView,其中 GridView 位于 ListView 的内部视图,并且指定了 ListView 项目源。我似乎没有找到怎么能。我得到 SelectedItem 或 GridView 的 SelectedItem 更改。 <ListView Grid.Row="4" Margin="0,250,0,0" ItemsSource="{Binding TestBinding}" SelectedItem="{Binding Path=selectedItem}" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left" SelectionChanged="ListView_SelectionChanged"> <ListView.View> <GridView AllowsColumnReorder="False" > <GridViewColumn Header="Test" DisplayMemberBinding="{Binding Path=Test1}" Width="100" /> <GridViewColumn Header="Test2" DisplayMemberBinding="{Binding Path=Test2}" Width="130" /> </GridView> </ListView.View> </ListView> 这是我的代码,它工作正常: public partial class MainWindow : Window, INotifyPropertyChanged, INotifyPropertyChanging { public class MyObj { public string Test1 { get; set; } public string Test2 { get; set; } } public MainWindow() { InitializeComponent(); TestBinding = new ObservableCollection<MyObj>(); for (int i = 0; i < 5; i++) { TestBinding.Add(new MyObj() { Test1 = "sdasads", Test2 = "sdsasa" }); } DataContext = this; } #region TestBinding private ObservableCollection<MyObj> _testBinding; public ObservableCollection<MyObj> TestBinding { get { return _testBinding; } set { if (_testBinding != value) { NotifyPropertyChanging("TestBinding"); _testBinding = value; NotifyPropertyChanged("TestBinding"); } } } #endregion #region selectedItem private MyObj _selectedItem; public MyObj selectedItem { get { return _selectedItem; } set { if (_selectedItem != value) { NotifyPropertyChanging("selectedItem"); _selectedItem = value; NotifyPropertyChanged("selectedItem"); } } } #endregion #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; // Used to notify the page that a data context property changed protected void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion #region INotifyPropertyChanging Members public event PropertyChangingEventHandler PropertyChanging; // Used to notify the data context that a data context property is about to change protected void NotifyPropertyChanging(string propertyName) { if (PropertyChanging != null) { PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); } } #endregion } 就我个人而言,我避免使用可观察的集合,因为我更喜欢对我的应用程序的功能进行更多控制。所以... 在 XAML 中,确保拼写为 SelectedItem="{Binding Path=SelectedItem}",注意大写 S。 然后,在您的 SelectionChanged 方法中,只需... private void myListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { var selectedItem = (yourModel)myListView.SelectedItem; }

回答 2 投票 0

如何将类中的常量字符串绑定到文本块

对于文本块,我需要从具有字符串的类中设置文本。 尝试从不同的类中设置文本,而不是直接将文本提供给文本属性。尝试通过路径绑定并传递字段...

回答 1 投票 0

“UserControl”是一个命名空间,但像类型一样使用

这是我的 CardDay.xaml 的代码,我使用 WPF 框架为我的天气应用程序设计了卡片视图,我在该框架中非常新并且正在学习 这是我的 CardDay.xaml 的代码,我在其中使用 WPF 框架为我的天气应用程序设计了卡片视图,我对这个框架非常陌生,正在学习 <UserControl x:Class="WeatherApp.UserControl.CardDay" 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" Name="cardDay"> <Border CornerRadius="10" Width="85" Padding="10" Margin="0 0 10 0" BorderThickness="1"> <Border.Style> <Style TargetType="Border"> <Setter Property="Background" Value="White"/> <Setter Property="BorderBrush" Value="#e9e9e9e9"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" Value="#03a9f4"/> </Trigger> </Style.Triggers> </Style> </Border.Style> <StackPanel> <TextBlock Text="{Binding Path=Day, ElementName=cardDay}" TextAlignment="Center" FontSize="14" FontWeight="SemiBold"/> <Image Source="{Binding Path=Source, ElementName=cardDay}" Width="30" Margin="0 10 0 10"/> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <TextBlock Text="{Binding Path=MaxNum, ElementName=cardDay}" TextAlignment="Center" FontWeight="SemiBold" Margin="0 0 8 0"/> <TextBlock Text="{Binding Path=MinNum, ElementName=cardDay}" TextAlignment="Center" FontWeight="SemiBold" Background="#7a7a7a"/> </StackPanel> </StackPanel> </Border> </UserControl> 这是 CardDay.xaml.cs 的代码,我猜它是我的天气应用程序的后端代码。我真的不太了解 C#,我正在学习,这是我第一次在项目中使用这种语言。 using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace WeatherApp.UserControl { public partial class CardDay : UserControl { public CardDay() { InitializeComponent(); } public string Day { get { return (string)GetValue(DayProperty); } set { SetValue(DayProperty, value); } } public static readonly DependencyProperty DayProperty = DependencyProperty.Register("Day", typeof(string), typeof(CardDay)); public string MaxNum { get { return (string)GetValue(MaxNumProperty); } set { SetValue(MaxNumProperty, value); } } public static readonly DependencyProperty MaxNumProperty = DependencyProperty.Register("MaxNum", typeof(string), typeof(CardDay)); public string MinNum { get { return (string)GetValue(MinNumProperty); } set { SetValue(MinNumProperty, value); } } public static readonly DependencyProperty MinNumProperty = DependencyProperty.Register("MinNum", typeof(string), typeof(CardDay)); public ImageSource Source { get { return (ImageSource)GetValue(SourceProperty); } set { SetValue(SourceProperty, value); } } public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(ImageSource), typeof(CardDay)); } } 您将能够看到 UserControl 带有红色下划线并且无法以任何其他方式工作。 public partial class CardDay : UserControl { public CardDay() { InitializeComponent(); } CardDay:UserControl 显示用作类型 我该如何解决它? 这件事真的很新鲜 尝试使用潜在的修复程序,但没有成功。 问题应该是显而易见的。看看你自己的代码: namespace WeatherApp.UserControl 您已经将您的命名空间称为UserControl。然后,您不能在代码中使用名称 UserControl 并期望它被解释为其他内容。一种选择是在使用类型名称时对其进行完全限定,例如 public partial class CardDay : System.Windows.Controls.UserControl 但这是一个坏主意。适当的做法是一开始就不要给你的命名空间命名得那么糟糕。我不确定什么可能更合适,因为我不知道它还应该包含什么,但一个选项可能是这样的: namespace WeatherApp.CardDayUserControl 尝试以描述性方式命名事物,以避免名称冲突。

回答 1 投票 0

如何获取 InputBinding 以在 WPF 列表视图上触发 MouseBinding 命令

这是一个常见问题,我在这里看到了很多问题的提出和回答。可悲的是,所有答案似乎都不适合我。如何让 DoubleClick 命令在 Li 中的 UserControl 上触发...

回答 1 投票 0

如何从 C# WPF 项目构建具有静态 .NET 运行时的单个 .exe 文件?

Visual Studio 2022 C# WPF 项目 我想分发单个 .exe 文件,而不要求目标计算机安装 .NET 6.0 运行时。 我只能在...中找到 C/C++ 代码生成的解决方案

回答 2 投票 0

WPF将LUT应用到Gray8图片

我有一张 Gray8 图片。 例如,从左到右从黑到白,但在真实的项目中,有真实的图片。 我的最终目标是在 255 处绘制橙白色像素,在

回答 1 投票 0

无法在 Windows Server Env 中加载文件或程序集“System.Runtime”错误

我将 WPF 项目从 .NET Framework 迁移到 .NET 6,该项目在我的本地系统(Windows 11)上构建良好。然而,当我转向 Azure 管道时,我们收到了此错误,并且可以复制它......

回答 1 投票 0

是否可以将 MahApps 的 TextBoxHelper 应用于 ScrollViewer?

我正在构建一个 WPF 应用程序,其中有一个 TextBox。要对其应用圆角,在这里我读到我需要使用边框内的 ScrollViewer 创建特定的样式。到目前为止一切顺利,b...

回答 1 投票 0

Mahapps Metro - Expander:将 LayoutTrasform 应用到标题更改样式

在使用 Mahapps Metro 的 WPF 应用程序中,我想在右侧使用 Expander。 为了防止 Expander 在折叠时占用太多空间,我想将 layoutTrasform 应用于其标题。

回答 1 投票 0

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