datagrid

Can I access ItemsHost of ItemsControl using reflection?

删除回忆录丶 提交于 2019-12-30 09:58:32
问题 I'm creating custom ItemsControl that is derived from DataGrid . I need to access ItemsHost that is the Panel that actually holds rows of DataGrid . I have seen som ugly tricks to do that but I consider them worse then using reflection. So can I access ItemsHost using reflection ? And how ? 回答1: Yes I can. It is simple - I've just created property in class inheriting from DataGrid : protected Panel ItemsHost { get { return (Panel) typeof (MultiSelector).InvokeMember("ItemsHost", BindingFlags

Silverlight DataGrid how to get cell value from a selected item?

断了今生、忘了曾经 提交于 2019-12-30 09:53:11
问题 I am trying to get a cell value from the selected item of a silverlight datagrid. In the attached code I can get to the properties of the cell and change its forecolor, but I can not get the value of the cell. Can someone please let me know what I am doing wrong? Many thanks in advance for your help! private void FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataGrid dataGrid = sender as DataGrid; int selectedIndex = dataGrid.SelectedIndex; if (selectedIndex > -1)

Expand/Collapse button in a Silverlight DataGrid

霸气de小男生 提交于 2019-12-30 09:42:36
问题 I am using a RowDetailsTemplate in a Silverlight DataGrid to show row details. Setting RowDetailsVisibilityMode="VisibleWhenSelected" does not give a good user experience (only one row can be expanded at a time, all rows cannot be collapsed). What's the easiest way to add an expand/collapse button on each row so that the rows can be expanded/collapsed independently? 回答1: I've been meaning to blog my solution to this. I set the grid RowDetailsVisibilityMode to Collapsed and use a

WPF DataGridTemplateColumn. Am I missing something?

不想你离开。 提交于 2019-12-30 09:05:13
问题 <data:DataGridTemplateColumn Header="Name"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Name}"> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> <data:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <TextBox Text="{Binding Name}"> </DataTemplate> </data:DataGridTemplateColumn.CellEditingTemplate> </data:DataGridTemplateColumn> It's clear example of Template column, right? What could be wrong with that? So, here is the thing - when

Get column index by Column header in WPF DataGrid

允我心安 提交于 2019-12-30 08:33:15
问题 How to get the Column index or Column.DisplayIndex from its Column Header in WPF DataGrid ? I know the Column Header , want to get column index . 回答1: you could use DisplayIndex (be aware this will change if columns are resorted) var index = dataGrid.Columns.Single(c => c.Header.ToString() == "HeaderName").DisplayIndex; edited: thanks for suggestion from @AnHX 回答2: Look like "paul" have an small error. Here is my code: var index = dataGrid.Columns.Single(c => c.Header.ToString() ==

Custom DataGrid column with a CellTemplate and binding

北慕城南 提交于 2019-12-30 07:04:10
问题 I need to create a reusable DataGrid column with a custom CellTemplate. This CellTemplate should, among other things, contain a TextBlock control to which I need to bind values to display in the DataGrid. All examples I've seen so far specified the CellTemplate for a column directly when using it in a DataGrid's Columns property and also specified a Binding directly to the TextBlock, e.g.: <data:DataGrid> <data:DataGrid.Columns> <data:DataGridTemplateColumn Header="Name"> <data

WPF4 Datagrid doesn't sort on column headers

偶尔善良 提交于 2019-12-30 05:54:22
问题 I am trying to implement my first WPF application using an MVVM design pattern. I created an application that is databinding to an ObservableCollection<>. The application renders fine, but I expect the datagrid to re-sort the rows when I click on the column headers. I've researched posts that said: The data source has to implement IEnumerable, mine does. I need to set CanUserSortColumns and/or CanUserSort (on each column), I did. I could implement a custom sort by specifying the Sorting

Highlighting cells in WPF DataGrid when the bound value changes

…衆ロ難τιáo~ 提交于 2019-12-30 04:01:10
问题 I have a DataGrid that has its data refreshed by a background process every 15 seconds. If any of the data changes, I want to run an animation that highlights the cell with the changed value in yellow and then fade back to white. I sort-of have it working by doing the following: I created a style with event trigger on Binding.TargetUpdated <Style x:Key="ChangedCellStyle" TargetType="DataGridCell"> <Style.Triggers> <EventTrigger RoutedEvent="Binding.TargetUpdated"> <BeginStoryboard>

Smooth scrolling for WPF DataGrid

别等时光非礼了梦想. 提交于 2019-12-30 02:42:17
问题 I am using WPF datagrid, only modification I have in place is: <toolkit:DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="TextWrapping" Value="Wrap"/> </Style> </toolkit:DataGridTextColumn.ElementStyle> I have this modification so if the cell contents are longer, they stretch the line height, no text is hidden. Problem is with DataGrid's scrolling behaviour - it jumps whole lines when scrolling, which does not work well at all if the row is higher than one line

WPF DataGrid Sync Column Widths

送分小仙女□ 提交于 2019-12-30 01:06:18
问题 I've got two WPF Toolkit DataGrids , I'd like so that when the user resizes the first column in the first grid, it resizes the first column in the second grid. I've tried binding the width of the DataGridColumn in the second grid to the appropriate column in the first grid, but it doesn't work. I'd prefer to use all xaml, but I'm fine with using code behind as well. <tk:DataGrid Width="100" Height="100"> <tk:DataGrid.Columns> <tk:DataGridTextColumn x:Name="Column1" Width="50"/> </tk:DataGrid