Advanced Forum Search Results
-
Alright, I figured out the problem here. DataGridTextColumn creates TextBlocks with a Margin of 4. The ElementStyle gets applied to the TextBlock after it's been created, but styles don't override values that have been set explicitly. So that style setter isn't being applied. There are a couple of ways ...
-
In the above code, cellContents will be a reference to the actual FrameworkElement that is inside of the cell at the specified column and row. If it was a DataGridTextColumn, for example, you'd have a reference to the actual TextBlock that's inside of that cell. You could cast it to a TextBlock and then set TextBlock.Foreground ...
-
To use your example above, change the target type from DataGridTextColumn to TextBlock.
Style hstyle = new Style(typeof(TextBlock));
Setter set1 = new ...
-
Sorry about that; I can see how my reply could have been a little misleading. You definitely can style the cell contents. What I was saying is that DataGridColumns aren't FrameworkElements, so you can't style a column directly, since there is no DataGridColumn.Style property. The ElementStyle is not a style for the ...
-
There are 3 main styles you can set on a column: the CellStyle, the ElementStyle and the EditingElementStyle. The CellStyle is for a target type of DataGridCell and is used to style the cell container. The ElementStyle is for whatever display element the column uses (i.e. a DataGridTextColumn uses a TextBlock for its display ...
-
The PagedCollectionView exists so that you can separate a source collection into multiple pages. At any given time, the PCV only shows the number of items in its current page. Because both the DataGrid and the DataPager are using the same PCV, they will both only see the same 15 items. If you want to look at all the items, ...
-
The DataGrid recycles its rows (and therefore, cell contents) when you scroll around. GenerateElement will not necessarily be called again for each new row that you scroll into view, because the elements don't get re-generated, so your code that explicitly sets the DataContext isn't getting hit when you scroll around.
In ...
-
What are you trying to bind the Header to? The DataGridColumnHeader's DataContext is going to be the DataGridColumn.Header content by default. Did you mean to set the Source of the header binding as a Converter, or did you mean to set the Converter instead, because the way it's written now will attempt to bind the ...
-
Sure, you could do something like the following:
xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
...
<Style TargetType="dataprimitives:DataGridColumnHeader" x:Key="nameOfYourHeaderStyle">
<Setter ...
-
The DataGrid is meant to have distinct display and editing modes, so that the developer is able to control when values are being changed. If you have an editable element within the display template (i.e. an editable CheckBox within a TemplateColumn's CellTemplate), you'll end up bypassing the DataGrid's editing mode.. and thus ...