wpfdatagrid

How to improve performance of WPF Grid control (.NET 4.0/4.5)?

人走茶凉 提交于 2019-12-11 02:39:55
问题 Definition : Having 2D-array of string (about 10 columns, 1,600 rows, fixed length of 7-char) serving as a data source for WPF .NET 4.0 Grid control, the following code snippet has been used in order to populate the Grid with labels displaying values from array. Note : Grid was added to XAML and passed to the function PopulateGrid (see Listing 1.). The visual output is essentially a tabular data representation in read-only mode (no need for two-way binding). Problem : Performance is a key

WPF Toolkit Datagrid Headers and Empty Source

亡梦爱人 提交于 2019-12-11 02:22:11
问题 How could I make the Datagrid display the headers in case there's no row to display? My Datagrid is "completely" read-only with: "AutoGenerateColumns ="True" "CanUserAddRows="False" "CanUserDeleteRows="False" "CanUserResizeRows="False" "IsReadOnly"="True" If there's no row, then the headers aren't displayed, if I add even an empty row, then the headers are shown! Until now, I couldn't find any workaround/solution for that! Thx all Fred 回答1: AFAIK If there are no rows then there are no columns

Style all DataGridTextColumns via AttachedProperty

眉间皱痕 提交于 2019-12-11 01:39:18
问题 What I tried to do is create a Style to apply a WordWrap on all DataGridTextColumns in a Datagrid without explicitly setting it like this. <DataGrid ItemsSource="{Binding Lines}"> <DataGrid.Columns> <DataGridTextColumn Header="Column1" Binding="{Binding Path=Result1}"> <DataGridTextColumn.ElementStyle> <Style TargetType="{x:Type TextBlock}"> <Setter Property="TextWrapping" Value="Wrap"/> </Style> </DataGridTextColumn.ElementStyle> </DataGridTextColumn> </DataGrid.Columns> </DataGrid>

WPF dataGrid Find Single Cell's X and Y and set background colour

与世无争的帅哥 提交于 2019-12-10 23:17:55
问题 I have a typed dataset that is being bound to a datagrid (MVVM). I also have a list of Points (X and Y in the typed dataset) that say which cells have errors. The logic to detect this is complex and is run on the server end. My goal is to paint each cell's background a different colour if they have an error, (i.e. the list of points contains that Cell's X and Y). The dataGrid is defined as: <DataGrid x:Name="gridData" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" VerticalAlignment="Stretch

About re-templating correctly DataGrid

纵然是瞬间 提交于 2019-12-10 21:20:04
问题 I recently had this problem about scrolling and focus changing. I solved it by adding in my DataGrid the following: <DataGrid.Template> <ControlTemplate> <ItemsPresenter /> </ControlTemplate> </DataGrid.Template> The scrolling now works fine, but a new problem appeared: the DataGrid 's headers do not show anymore. It is actually logic, since now my DataGrid will only show an ItemsPresenter without taking care of the headers. I am therefore trying to define an appropriate template, showing

Issue with doubleclick on datagrid

懵懂的女人 提交于 2019-12-10 17:06:12
问题 I have the following on a datagrid in my C# code: <DataGrid.InputBindings> <MouseBinding Gesture="LeftDoubleClick" Command="{Binding CmdTransUnitFillerRowDblClick}" /> </DataGrid.InputBindings> It works for the most part except if user first selects the row (single click) and then tries double-clicking the row. In this situation the CmdTransUnitFillerRowDblClick code is never fired for processing. So, how can I get the CmdTransUnitFillerRowDblClick to fire correctly on a double-click when the

Stop CTRL-Click from affecting parent datagrid

自古美人都是妖i 提交于 2019-12-10 16:18:22
问题 I have a WPF DataGrid that has another datagrid declared within the RowDetailsTemplate; <DataGrid name="dataGrid1" RowDetailsVisibilityMode="VisibleWhenSelected"> ... <DataGrid.RowDetailsTemplate> <DataTemplate> <DataGrid name="dataGrid2"> ... </DataGrid/> </DataTemplate> </DataGrid.RowDetailsTemplate> </DataGrid> When I CTRL-Click a row on the child DataGrid, it un-selects the parent datagrid's SelectedItem and hides the RowDetailsTemplate . I assume this is some kind of Routed Event

Resize Datagrid Height after deselecting a RowDetailsTemplate

淺唱寂寞╮ 提交于 2019-12-10 14:55:31
问题 I am using RowDetailsTemplate to display a nested datagrid for a row. Now the datagrid expands in height when I select a row to show this nested datagrid. But it doesn't reduce its height when the row is deselected. Is there a way to resize the datagrid to its original height after the row details have been collapsed? Is it possible to do it declaratively? 回答1: Place detail into StackPanel and grid with this this Behaviour: public class DataGridDetailResizeBehavior : Behavior<FrameworkElement

How to rollback changes to WPF DataGrid control using LINQ-to-SQL?

你。 提交于 2019-12-10 14:24:13
问题 I was able to set up a WPF Datagrid, display a Northwind database table via linq-to-sql, and handle the TheDataGrid_RowEditEnding event so that it saves back the the database. However, when a CustomerID was changed, it gets an error from the database which I handle, but how do I now either (1) rollback the Datagrid control or (2) refetch the original data from the database view LINQ-to-SQL (the refetching that I do below via LINQ seems to have some kind of caching, it doesn't refresh): <Grid

How to determine whether a WPF DataGrid is in edit mode? [duplicate]

青春壹個敷衍的年華 提交于 2019-12-10 14:04:43
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Code to check if a cell of a DataGrid is currently edited Is there a way to determine whether a WPF DataGrid is in edit mode / which row is currently edited? 回答1: VB.NET <Extension> Public Function GetContainerFromIndex(Of TContainer As DependencyObject) _ (ByVal itemsControl As ItemsControl, ByVal index As Integer) As TContainer Return DirectCast( itemsControl.ItemContainerGenerator.ContainerFromIndex(index),