wpfdatagrid

Binding multifunctional WPF DataGrid

房东的猫 提交于 2019-12-07 11:07:03
问题 How would you go about binding a WPF datagrid that needs to display data from many different datasources with varying number of columns with different column headers and types? What I'm currently doing is creating a custom List<DataGridColumn>() list of datagrid columns in my ViewModel for each different collection of records to be displayed in this DataGrid. I Loop over this List to set the DataGrid columns: foreach (DataGridColumn dgc in dgcSample) { dgc.HeaderStyle = hStyle; dgMyDataGrid

does the wpf datagrid have a virtual mode like the winforms DataGridView?

最后都变了- 提交于 2019-12-07 09:51:35
问题 The winforms DataGridView has a virtual model and uses the OnCellValueNeeded method to gets cell values from a a user defined data store. How do i do this in wpf? The DataGrid doesn't seems to have a OnCellValueNeeded method. Thanks 回答1: Not sure if this already helps you: DataGrid uses UI virtualization , what means that objects are not created before they are visible on screen and the corresponding properties of your source objects will not be called as long as they are not visible. It

Wpf datagrid validationrule for unique field

心已入冬 提交于 2019-12-07 08:47:25
问题 I've got a suclassed ValidationRule named UniqueNameSolidWoodRule to validate for duplicate entries in a datagrid. Here's the code: public class UniqueNameSolidWoodRule : ValidationRule { public CollectionViewSource CurrentCollection { get; set; } public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (value != null) { ObservableCollection<SolidWood_VM> castedCollection = (ObservableCollection<SolidWood_VM>)CurrentCollection.Source; foreach (SolidWood_VM swVM in

CellStyle based on RowStyle in WPF

纵饮孤独 提交于 2019-12-07 06:05:10
问题 I have a WPF DataGrid represented in XAML . I'm using a RowStyle for my grid's TableView but also need to set some properties for specific cells. I need those cells to have the properties of the row style and apply the extra properties from the cell style on top of those. What I would need is something like this, although this doesn't work as it's saying: Target type 'CellContentPresenter' is not convertible to base type 'GridRowContent' <Style x:Key="MyGridRowStyle" BasedOn="{StaticResource

WPF DataGrid validation/binding mode bug

北城以北 提交于 2019-12-07 05:42:23
问题 I created a new project, very simple, to test only the Microsoft WPF DataGrid behavior. Nothing else involved, I only use the standard DataGrid: <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <DataGrid

How to prevent columns from not displaying in WPF datagrids when using '/' in the header? [duplicate]

北慕城南 提交于 2019-12-07 05:02:15
问题 This question already has answers here : What is it about DataTable Column Names with dots that makes them unsuitable for WPF's DataGrid control? (4 answers) Closed 5 years ago . I have a WPF Datagrid in my application where I set the value of the ItemSource to the DefaultView of a DataTable that I have constructed. The problem lies in the fact that whenever I set the ColumnName of one of the columns in my DataTable to a string that includes '/' the header shows up in the DataGrid control but

WPF Date String Format in XAML [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-07 04:50:16
问题 This question already has answers here : WPF Binding StringFormat Short Date String (7 answers) Closed 4 years ago . I am trying to format string after a date has been selected by the DatePicker. The Format that I am getting is "9/5/2013 12:00:00 AM" and what I am trying to get is "9/5/2013". Can someone tell me what I am doing wrong with the string format? <DataGridTemplateColumn Header="Start"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Start,

Conditional Formatting of WPF DataGrid Cell Depending on DataType

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 16:05:23
I have a user control that inherits from the WPF DataGrid control and to which I pass different List of objects and, so, the columns of the grid depend (i.e. are automatically generated) on the class of object that I send through. <userc:cfDataGrid x:Name="grdResults" FontStyle="Normal" FontFamily="Microsoft Sans Serif" FontSize="14" RowHeight="30" AutoGenerateColumns="True" Margin="12" AlternatingRowBackground="Gainsboro" AlternationCount="2" ItemsSource="{Binding Results}" IsReadOnly="True" HeaderNames="{Binding Headers}" > </userc:cfDataGrid> Now, I'd like to also pass through a list of

Styling the Xceed ColumnManagerCell

不问归期 提交于 2019-12-06 15:59:53
问题 I'm interested in styling the column headers on an Xceed DataGrid. The goal is to make the background color grey, with a dark grey border around each header column cell. It seemed to me like the best way to do this was to style the ColumnManager: <Style TargetType="{x:Type xcdg:ColumnManagerCell}"> <Setter Property="Template" Value="{StaticResource ColumnManagerCellTemplate}"/> <Setter Property="BorderBrush" Value="#c5c5c5"/> <Setter Property="BorderThickness" Value="1,1,1,1"/> </Style> Using

WPF DataGrid, cross out the row

╄→尐↘猪︶ㄣ 提交于 2019-12-06 15:00:20
is it possible to cross out some rows in DataGrid? I think you'll have to re-template DataGridRow for this. Played around with it a bit and got the result seen below. Hopefully this is what you had in mind The "cross" Visibility is Binding to a Property called IsCrossed <DataGrid ...> <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/> <Setter Property=