wpf 相关问题

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

如何在 C# 中处理到 Xaml 的动态绑定

我正在尝试通过从 viewmodel.cs 启动来动态更新我的 xaml 程序上的绑定 由于某种原因,我无法在我的 CS 中的 label.content 上显示绑定: 每次我跑步的时候,eit...

回答 1 投票 0

使用 WPF 以编程方式更改语言/资源

我有一个 DropDown(如果这很重要,请使用 MahApps),我想用它在我的程序中“动态”切换语言。 语言班 名称空间 SAM { 公开课语言 {

回答 2 投票 0

WPF:基于列索引的绑定

在 WPF 中,如何基于 DataGrid 单元格的列索引创建数据触发器?我可以访问该列,但该列只有 DisplayIndex 可用,而不是真正的索引。我需要设计风格...

回答 2 投票 0

Alt 键跳过 KeyDown、KeyUp 事件

如果我按下某个键,然后触摸 Alt 键,则按下的键不会触发 KeyUp 事件,直到下次我按下重复的键(即“aaaaaaaaa...”)。就像...

回答 1 投票 0

WPF - 如何使 ListBox 在 MVVM 中“选择时”运行函数?

我正在制作一个统计绘图辅助程序。我是 WPF 的新手。 我已经有 2 个列表框: 简介列表 比赛文件夹列表 首先,我想从第一个中选择(选择)个人资料

回答 1 投票 0

选择监视器以显示 WPF 应用程序

我正在开发 WPF 应用程序,我想选择显示窗口的监视器。我的.NET版本是8.0,SO是Windows,版本是7.0。 我正在尝试应用 Mostlytech 步骤,...

回答 1 投票 0

带参数的依赖注入

我有一个WPF应用程序。在左侧的主窗口中,是一个包含多个条目的列表框,右侧是一个 ContentControl,当选择其中一个条目时,UserControl 会随之...

回答 1 投票 0

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

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