datagridcell

Selection does hide the DataGridCell

冷暖自知 提交于 2021-01-28 12:30:52
问题 I have a data grid: <DataGrid x:Name="grid1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding}" IsReadOnly="True" Loaded="grid1_Loaded" AutoGeneratingColumn="grid1_AutoGeneratingColumn" SelectionUnit="Cell" MouseMove="Grid1_MouseMove" LoadingRow="grid1_LoadingRow" MouseLeave="grid1_MouseLeave"> <DataGrid.Resources> <Style TargetType="{x:Type DataGridCell}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridCell}">

WPF - How to get a cell from a DataGridRow?

荒凉一梦 提交于 2020-06-24 08:42:25
问题 I have a data-bound DataGrid with alternating row background colors. I would like to color a cell differently based on the data it contains. I have tried the solution suggested by this thread http://wpf.codeplex.com/Thread/View.aspx?ThreadId=51143 But, DataGridCellsPresenter presenter = GetVisualChild(row) always returns null. I am using public static T GetVisualChild<T>(Visual parent) where T : Visual { T child = default(T); int numVisuals = VisualTreeHelper.GetChildrenCount(parent); for

How to change background of DataGridCell when IsEditing=True in WPF

非 Y 不嫁゛ 提交于 2020-01-05 18:56:26
问题 Setting background works fine for DataGridCheckBoxColumn but not for DataGridTextColumn . I set it for cell in resources: <Style TargetType="{x:Type DataGridCell}"> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="#ffff00" /> </Trigger> <Trigger Property="IsEditing" Value="True"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="#00ff00" /> <Setter Property="Background" Value="#00ff00" /> </Trigger> </Style

Wpf DataGrid - Unable to select cells programmatically

两盒软妹~` 提交于 2020-01-05 04:03:58
问题 I need to select all the cells of a column which header was clicked , i took this from the following post : Selecting all Cells in Column when a certain column is clicked i wan't to select all it's respected cells. cs : private void OnColumnsClicked(object sender, RoutedEventArgs e) { var columnHeader = (DataGridColumnHeader)e.OriginalSource; this.AssociatedObject.SelectedCells.Clear(); for (int i = 0; i < this.AssociatedObject.Items.Count; i++) { var cellInfo = new DataGridCellInfo(this

Select DataGridCell from DataGrid

不想你离开。 提交于 2019-12-29 07:35:09
问题 I have a DataGrid WPF control and I want to get a specific DataGridCell . I know the row and column indices. How can I do this? I need the DataGridCell because I have to have access to its Content. So if I have (for example) a column of DataGridTextColum , my Content will be a TextBlock object. 回答1: You can use code similar to this to select a cell: var dataGridCellInfo = new DataGridCellInfo( dataGrid.Items[rowNo], dataGrid.Columns[colNo]); dataGrid.SelectedCells.Clear(); dataGrid

Accessing control between DataGridCells, dynamic cascading ComboBoxes

好久不见. 提交于 2019-12-18 09:38:23
问题 I have a DataGrid that two of its columns are ComboBoxes (one contains few but not this is the problem). I want, that when the user changes the first Combo's value, the ComboBox in the other column should bind to a property of its (this property is a collection). Say the First ComboBox is Category, I want that when the user changes its value, the other CB is populated with the values of (first combo's selected category).Vendors. How should I do it, I don't use MVVM, just simple WPF. I don't

Color DataGridCell by Cellvalue

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 03:59:52
问题 i've a WPF DataGrid with different count of columns. I want to color the single cells dependent by the value. For example: If the cell-value is 0, then red. These are my experiments: <DataGrid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" x:Name="DataGrid" SelectionUnit="Cell"> <DataGrid.CellStyle> <Style TargetType="{x:Type DataGridCell}"> <Style.Triggers> <!--experiment 1 --> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Value, NotifyOnSourceUpdated=True,

WPF DataGrid Binding DataGridCell Content

主宰稳场 提交于 2019-12-10 15:46:58
问题 This is hopefully going to be a really simple answer, I'm just not seeing the proverbial wood for the trees I think. I've got a DataGridCell style in which I want to bind the content of the cell to the source property of an image, here's the XAML I'm using at the moment: <Style x:Key="DataGridImageCellStyle" TargetType="{x:Type toolkit:DataGridCell}"> <Setter Property="Background" Value="Transparent" /> <Setter Property="BorderBrush" Value="Transparent" /> <Setter Property="BorderThickness"

How to style a WPF DataGridCell dynamically

只愿长相守 提交于 2019-12-08 01:41:27
问题 I have a DataGrid with the itemsSource defined as follow: dg.ItemsSource = new ObservableCollection<myRow> ... public class myRow : Collection<myDataGridCell> { ... } ... public interface ImyDataGridCell { Brush Background { get; set; } Brush Foreground { get; set; } } and then I have classes for each type of column/cell: public class myTextBoxColumn : DataGridTextColumn {...} public class myTextBoxCell : TextBox, ImyDataGridCell {...} then I set each column's CellStyle like this: in each

WPF Datagrid Cell with Validation Error Style

亡梦爱人 提交于 2019-12-07 04:44:11
问题 I am trying to change the default style of a DataGridCell (within a WPF Toolkit DataGrid) when there is a validation error. The default is a red border. How can I put my own template? Thanks. 回答1: Try this: <!-- Cell Style --> <Style x:Key="CellErrorStyle" TargetType="{x:Type TextBlock}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> <Setter