Tag: xaml

你如何突出TreeViewItem?

我有一个简单的树视图,包含所有默认颜色。 单击某个项目时,它会突出显示,背景变为蓝色。 好到目前为止。 我正在尝试在后面的代码中执行相同的操作,以便我可以使用蓝色突出显示我选择的树视图项。 我发现我发现改变背景的唯一属性是“.IsSelected”。 但是当我将其设置为true时,树视图项目以白色突出显示。 我不明白。 我没有将高亮颜色设置为任何东西,那么为什么它会选择与使用鼠标单击选择相同项目时不同的高亮颜色? “突出显示”是一个与“选择”不同的属性,如果是,那么该属性的名称是什么? 谢谢。 编辑:添加代码(我的道歉,这很简单所以我认为没有人会想看到代码) Xaml :(是的,这是整个代码。只需将其插入项目即可运行。) AddNode 代码背后: using System.Windows.Shapes; using System.IO; namespace TestTreeView { public partial class Window1 : System.Windows.Window { public Window1() { InitializeComponent(); } public void btnClick(object sender, RoutedEventArgs e) { TreeViewItem n1 = new TreeViewItem(); n1.Header = “Top Node”; n1.IsSelected = true; n1.Focus(); treeView.Items.Add(n1); […]

如何在wpf datagrid中删除所选行(使用复选框)

我的WPF DataGrid是: 另外Dynamicaly我正在将数据填充到datgrid。在xaml.cs文件中,我编写了下面给出的代码,用于从数据网格中删除所选行但是它在行中抛出错误 DataGridRow item =(DataGridRow) datagrid1.ItemContainerGenerator.ContainerFromItem(datagrid1.Items[j]); 所以请查看下面给出的代码,我为此做了同样的代码。 private void Button_Click_1(object sender, RoutedEventArgs e) { for (int j = 0; j < datagrid1.Items.Count; j++) { DataGridRow item =(DataGridRow) datagrid1.ItemContainerGenerator.ContainerFromItem(datagrid1.Items[j]); CheckBox ckb = (CheckBox)GetVisualChild(item); if (ckb.IsChecked.Value) { DataRowView drv = (DataRowView)datagrid1.Items[j]; //delete the row- updating to the database } } } static T GetVisualChild(Visual parent) where […]

使用LINQ从xml填充List

我是LINQ的新手。 我需要使用xml中的信息填充以下类的List 。 class Person { int id; string name; string address; } List people = new List(); 在LINQ中执行此操作的正确方法是什么。 … … … 1 NameA AddressA 2 NameB AddressB .. .. 我需要知道LINQ表达式的结构才能直接到达标签。 此外,是否有任何用于填充List’, ie map快捷方式,即将Person List’, ie map to Instance`标签。

通过XAML在WPF中的TextBox的TextChanged事件上启用/禁用Button

WPF中有TextBox和Button控件: 如果更改了BackUpTextBox的文本,则必须启用Button BackUpSave。 我知道如何通过C#代码通过BackUpTextBox TextChanged事件来做到这一点。 但有没有办法通过XAML表示法启用/禁用按钮?

WPF使用datatemplate中的转换器从xaml文本和手机8上的XamlReader创建

我正在使用像这样的文本xaml生成DataTemplate: var dataTemplate = (DataTemplate)XamlReader.Load(xaml.ToString()); 其中一个元素是CheckBox与它的转换器绑定,指向StaticResource: StringBuilder xaml = new StringBuilder(); xaml.AppendFormat(@” “); 文本中存在此转换器引用会导致手机上的Application_UnhandledException中捕获到exception。 消息如下所示: – InnerException {System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component. at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.UIElement_Measure_WithDesiredSize(UIElement element, Size availableSize) at System.Windows.UIElement.Measure_WithDesiredSize(Size availableSize) at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(UIElement child, Size layoutSlotSize) at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, […]

在DataGridCell的CellEditingTemplate中查找TextBox

我在WPF中遇到问题,在选择单元格并处于编辑模式时,以编程方式访问DataGridTemplateColumn.CellEditingTemplate中的文本框。 这是我的DataGrid的XAML: 如何在选择单元格时访问该TextBox? 这是一个显示DataGrid可视树的图像,如果它可以帮助您: 我在DataGridCell GotFocus事件中尝试了以下操作,但没有运气。 它只是返回NULL,因为找不到它。 private void DataGridCellGotFocus(object sender, RoutedEventArgs e) { var cell = sender as DataGridCell; var textBox = FindChild(cell, null); } FindChild方法的位置如下: /// /// Finds a Child of a given item in the visual tree. /// /// A direct parent of the queried item. /// The type of the queried […]

我在哪里可以获得眼球的XAML路径?

我有一个明星看起来像: Data=”M 61.3431396484375,0 C61.3431396484375,0 80.2991943359375,38.40919494628906 80.2991943359375,38.40919494628906 80.2991943359375,38.40919494628906 122.686279296875,44.56840515136719 122.686279296875,44.56840515136719 122.686279296875,44.56840515136719 92.01470947265625,74.46580505371094 92.01470947265625,74.46580505371094 92.01470947265625,74.46580505371094 99.25527954101562,116.68159484863281 99.25527954101562,116.68159484863281 99.25527954101562,116.68159484863281 61.3431396484375,96.75 61.3431396484375,96.75 61.3431396484375,96.75 23.430999755859375,116.68159484863281 23.430999755859375,116.68159484863281 23.430999755859375,116.68159484863281 30.67156982421875,74.46580505371094 30.67156982421875,74.46580505371094 30.67156982421875,74.46580505371094 0,44.56840515136719 0,44.56840515136719 0,44.56840515136719 42.3870849609375,38.40919494628906 42.3870849609375,38.40919494628906 42.3870849609375,38.40919494628906 61.3431396484375,0 61.3431396484375,0 z”

ComboBox绑定到自定义ViewModel

我正在开发一个WPF项目。 这是我的XAML代码: 这是我的ViewModel代码: // BrowserInstance is a simple struct with two public fields: // 1) System.Diagnostics.Process Process // 2) System.String Name public sealed class BrowsersViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private BrowserInstance m_SelectedItem; public BrowserInstance SelectedItem { get { return m_SelectedItem; } set { if (m_SelectedItem != value) { m_SelectedItem = value; NotifyPropertyChanged(“SelectedItem”); […]

仅在WPF / XAML中hover的图像上投下阴影效果或模糊效果

我有一个shadow属性定义如下的图像。 这会生成带边框的图像。 好。 但是,我需要仅在图像hover时显示边框? 我怎么做 ? 另外,如何模糊hover在它上面的图像? 非常感谢。

如何在Datagrid中为第一行设置颜色

我在wpf(mvvm)项目上有一个datagrid。 datagrid排序显示作为第一行添加到集合的最后一项。 我想为第一行着色(为了突出显示添加到集合中的新项目)我已经看到了一些关于这种方式的类似问题,但它们都没有真正与我正在寻找的相关。 我试图使用IValueConverter,但它似乎不适合我,因为我需要获得第一行的唯一标识符并更改所有其余行,以便将其归类为“第一行”。 我对集合中项目的对象模型如下所示: public class Messages { public string Date {get; set;} public string Sender{get; set;} public string Content{get; set;} } *编辑忘记添加转换器代码…当然这会将所有行着色为红色,因为我不知道如何在集合更改时影响其他行。 class DateToColorConverter : IValueConverter { object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (Convert.ToDateTime(value) >= DateTime.Now.AddMinutes(-1)) { return “Red”; } else return “Yellow”; } object IValueConverter.ConvertBack(object value, Type […]