Tag: wpf

树视图中任何项目的OnExpanded事件

我希望在我的树视图中获得任何扩展树视图的事件。 原因如此,与原始问题有点无关:我正在创建一个与xml文件树紧密相关的树,但我允许在xml中包含一个include元素,因此树可以跨多个文件。 我想在扩展时在treeview中设置treeviewitems的itemssource属性。

如何在没有焦点的情况下突出显示/选择wpf文本框中的文本?

我希望在文本框未聚焦时突出显示wpf文本框中的所选文本。 在我的应用程序中,我的文本框永远不会得到焦点,并且每个键输入都是手动完成的。 我想知道当文本框没有聚焦时是否有办法突出显示所选文本? 任何帮助,将不胜感激!

WPF:如何防止控件窃取关键手势?

在我的WPF应用程序中,我想将一个输入手势附加到命令,以便输入手势在主窗口中全局可用,无论哪个控件具有焦点。 在我的情况下,我想将Key.PageDown绑定到命令,但是,只要某些控件接收焦点(例如TextBox或TreeView控件),这些控件就会接收键事件并且不再触发命令。 这些控件没有定义特定的CommandBindings或InputBindings 。 这是我定义输入手势的方式: XAML: 码: using System; using System.Windows; using System.Windows.Input; public static class Commands { private static RoutedUICommand _myCommand; static Commands() { _myCommand = new RoutedUICommand(“My Command”, “My Command”, typeof(Commands), new InputGestureCollection() { new KeyGesture(Key.PageDown, ModifierKeys.None) }); } public static ICommand MyCommand { get { return _myCommand; } } } public partial […]

碰撞检测实施

我有一个碰撞检测类,它通过查找中心之间的距离以及该距离是否足够小而成为碰撞(参见碰撞检测错误 )。 我的问题是试图使这个实际工作,椭圆碰撞。 如有必要,我会解释更多。 谢谢

WPF弹出窗口

我想让用户在点击按钮后选择他们的选项。 例如,在模式弹出窗口中显示两个按钮,“立即重启”和“稍后重启”将是我的首选。 使用MessageBox不是我的解决方案,因为它不允许用户更改按钮的标题。

PreviewKeyDown没有看到Alt-modifiers

我有一些(应该是)捕获击键的代码。 顶层窗口有一个 Keyboard.PreviewKeyDown=”Window_PreviewKeyDown” 子句和支持CS文件包含: private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { switch (e.Key) { case Key.L: btnPrev_Click(sender, new RoutedEventArgs()); e.Handled = true; break; case Key.R: btnNext_Click(sender, new RoutedEventArgs()); e.Handled = true; break; } } } 现在工作正常, CTRL L和CTRL R都调用相关函数。 一旦我将modifer check更改为使用ModifierKeys.Alt ,它就会停止工作。 换句话说, ALT L和ALT R都不会调用这些函数。 我在这里想念的是什么?

WPF – 将UserControl的可见性绑定到属性

我有一个绑定到ObservableCollection的ListView。 数据从Internet加载,然后添加到集合中。 下载需要几秒钟,我想指示用户数据正在加载。 我创建了一个指示活动的UserControl。 我将它放在ControlTemplate中。 我想将ActivityIndicatorControl Visibility绑定到一个属性,让我们说bool IsLoading并相应地将它设置为Visible / Collapsed。 谢谢!

如何将Foreground绑定到ViewModel中的属性?

我想将TextBlock的foreground属性绑定到ViewModel中的Property。 这不起作用: 编辑 查看: TextBlock Text=”{Binding Path=FullName, Mode=OneWay}” Foreground=”{Binding Path=ForegroundColor}” Margin=”0 5 3 5″ 代码背后: CustomerHeaderViewModel customerHeaderViewModel = new CustomerHeaderViewModel(); customerHeaderViewModel.LoadCustomers(); CustomerHeaderView.DataContext = customerHeaderViewModel; 查看型号: private System.Windows.Media.Brush _foregroundColor; _foregroundColor = System.Windows.Media.Brushes.DarkSeaGreen; public System.Windows.Media.Brush ForegroundColor { get { return _foregroundColor; } set { _foregroundColor = value; OnPropertyChanged(“ForegroundColor”); } } public CustomerHeaderViewModel() { ForegroundColor = System.Windows.Media.Brushes.Red; } […]

获取TreeView中所选项的TreeViewItem

我有一个TreeView绑定到具有父子关系的数据集。 我将如何从TreeView获取seleted TreeViewItem? 请帮我。 我的代码如下。 XAML: – public MainWindow() { InitializeComponent(); DataSet ds = new BL.BLMenu().GetAllMenues(new BOModule { Name = Modules.Personnel }); ds.Tables[0].TableName = “Menu”; DataRelation relation = new DataRelation(“rsParentChild”, ds.Tables[“Menu”].Columns[“MenuId”], ds.Tables[“Menu”].Columns[“ParentId”]); relation.Nested = true; ds.Relations.Add(relation); BOMenu mnu = new BOMenu(); BOMenu.RootNodes = ds.Tables[“Menu”].DefaultView; BOMenu.RootNodes.RowFilter = “ParentId IS NULL”; this.DataContext = this; stbiDate.Content = DateTime.Now; […]

在Windows中自动完成文本框和“在键入时隐藏指针”

如何通过应用程序禁用“键入时隐藏指针”选项? 我遇到了光标隐藏的问题,没有按下转义或丢失窗口焦点而没有将其恢复。 该应用程序是用C#编写的,并使用WPF。 不需要技术特定的答案,因为它可能使用任何技术。 这是场景:用户可以键入TextBox,并在框下方显示自动完成列表。 一旦用户开始输入,他/她就不能再从下拉列表中选择项目,因为没有鼠标光标。 我注意到Firefox没有这种行为。 例如,在地址栏中键入URL时,鼠标光标永远不会消失。 还有其他地方我见过这种行为所以我知道它一定是可能的。 任何帮助是极大的赞赏!