datagridcell

How to style a WPF DataGridCell dynamically

允我心安 提交于 2019-12-06 06:00:01
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 column's constructor: string source = String.Format(CultureInfo.InvariantCulture, "[{0}].", dataGrid

WPF DataGridCell Template with TextBlock - Binding?

余生长醉 提交于 2019-12-05 12:22:08
i replace the ContentPresenter in the DataGridCell 's Template with a TextBlock an now i search for the correct Binding to the content. The normal way is Text="{TemplateBinding Content} for the TextBlock - it doesn't work. Also Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Content, Mode=TwoWay}" doesn't work correct. Any other ideas? Suppose you have changed the DataGridCell Template to the following <ControlTemplate TargetType="{x:Type DataGridCell}"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="

WPF DataGrid Cell Text Wrapping - set to NoWrap (False)

不问归期 提交于 2019-12-02 08:04:25
问题 How do I set the TextWrapping of every cell in a WPF DataGrid to "NoWrap"? I understand the Cell itself does not have a "TextWrapping" property, but I'd like to set the property on the control within the cell. The DataGrid I am working with does not have columns defined explicitly, the result set it is displaying is dynamic. I am looking for a solution similar to the answers provided in the links below. However I do not want to explicitly override the cell style/template and define the

How to get a cell from DataGrid?

故事扮演 提交于 2019-12-02 07:27:26
I have a DataGrid (.net framework 3.5, WPFToolKit). And i want to change borders (left or right) of some cells. One, two or three. So how can I get an access to a single cell? And is it possible? I've found some solutions, but they are for .net 4. denis morozov You can extend the DataGrid and add the following, NOTE: it's just a sample, you don't need to do some of the processing that I am doing: public DataGridCell GetCell(int row, int column) { var rowContainer = GetRow(row); if (rowContainer != null) { var presenter = FindVisualChild<DataGridCellsPresenter>(rowContainer); if (presenter ==

How to get a cell from DataGrid?

雨燕双飞 提交于 2019-12-02 06:57:04
问题 I have a DataGrid (.net framework 3.5, WPFToolKit). And i want to change borders (left or right) of some cells. One, two or three. So how can I get an access to a single cell? And is it possible? I've found some solutions, but they are for .net 4. 回答1: You can extend the DataGrid and add the following, NOTE: it's just a sample, you don't need to do some of the processing that I am doing: public DataGridCell GetCell(int row, int column) { var rowContainer = GetRow(row); if (rowContainer !=

WPF DataGrid Cell Text Wrapping - set to NoWrap (False)

折月煮酒 提交于 2019-12-02 04:17:55
How do I set the TextWrapping of every cell in a WPF DataGrid to "NoWrap"? I understand the Cell itself does not have a "TextWrapping" property, but I'd like to set the property on the control within the cell. The DataGrid I am working with does not have columns defined explicitly, the result set it is displaying is dynamic. I am looking for a solution similar to the answers provided in the links below. However I do not want to explicitly override the cell style/template and define the control to be used. Instead I would like to say, IF a TextBlock is being used, set its TextWrapping property

Problems binding to a the content of a WPF DataGridCell in XAML

扶醉桌前 提交于 2019-12-01 01:12:45
I used the following post to implement a datagrid bound to a list of dynamic objects Binding DynamicObject to a DataGrid with automatic column generation? The ITypedList method GetItemProperties works fine, a grid is displayed with all the columns I described. I use a custom PropertyDescriptor and override the GetValue and SetValue methods as described in the above post, I also implement the TryGetMember and TrySetMember methods in the dynamic objects. so basically I have a ComplexObject:DynamicCobject with a field Dictionary and a ComplexObjectCollection implementing ITypedList and IList.

Problems binding to a the content of a WPF DataGridCell in XAML

ε祈祈猫儿з 提交于 2019-11-30 21:10:38
问题 I used the following post to implement a datagrid bound to a list of dynamic objects Binding DynamicObject to a DataGrid with automatic column generation? The ITypedList method GetItemProperties works fine, a grid is displayed with all the columns I described. I use a custom PropertyDescriptor and override the GetValue and SetValue methods as described in the above post, I also implement the TryGetMember and TrySetMember methods in the dynamic objects. so basically I have a ComplexObject

WPF DataGrid: How to Determine the Current Row Index?

ぃ、小莉子 提交于 2019-11-30 08:25:03
I am trying to implement a very simple spreadsheet functionality based on a DataGrid. The user clicks on a cell The user types a value and presses return The current row is scanned and any cell formula that depends on the clicked cell is updated. This seems to be the best event handler for my requirements: private void my_dataGrid_CurrentCellChanged(object sender, EventArgs e) Question: How do I detect the row index of the current row? Try this (assuming the name of your grid is "my_dataGrid"): var currentRowIndex = my_dataGrid.Items.IndexOf(my_dataGrid.CurrentItem); Normally, you'd be able to

Select DataGridCell from DataGrid

喜夏-厌秋 提交于 2019-11-29 09:45:08
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. 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.SelectedCells.Add(dataGridCellInfo); dataGrid.CurrentCell = dataGridCellInfo; I can't see a way to update the contents