wpfdatagrid

How to set DataGrid's row Background, based on a property value using data bindings

跟風遠走 提交于 2019-11-28 04:27:23
In my XAML code, I want to set the Background color of each row, based on a value of the object in one specific row. I have an ObservableCollection of z , and each of the z has a property called State . I started out with something like this in my DataGrid : <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <Setter Property="Background" Value="{Binding z.StateId, Converter={StaticResource StateIdToColorConverter}}"/> </Style> </DataGrid.RowStyle> This is a wrong approach because x is not a property in my ViewModel class. In my ViewModel class I have an ObservableCollection<z> which is the

ListView.GridViewColumn (*) width

倾然丶 夕夏残阳落幕 提交于 2019-11-28 03:56:50
I am using ListView control instead of DataGrid in my WPF application. I want to give * width to my ListView.GridViewColumn , but whenever I am providing * width to ListView.GridViewColumn , it gives me a compile time error. Kindly suggest me how can I provide * width to ListView.GridViewColumn , so that ListView.GridViewColumn can automatically fill extra space when I maximize screen. Any help on this will highly appreciated. Thanks Bilal Hashmi Please try that solution: <ListView> <ListView.View> <GridView> <GridViewColumn Header="column1" x:Name="col1"/> <!--Column that shall resize: Width

how to handle group subtotal and e.g. target rows in WPF DataGrid?

老子叫甜甜 提交于 2019-11-28 02:54:12
问题 I'm implementing a WPF DataGrid that contains projects with many key figures. Projects are grouped by project categories. For each category there should be: a row that shows in each key figure column sum of all rows for the column. a target row that is not part of the datasource grid in binded to. target row tells for every column what is target for the year (e.g. how much money there's to spend). These rows should be always on top in each group (sorting filtering). My 1st solution was to

How do I bind the background of a data grid row to specific color?

拟墨画扇 提交于 2019-11-28 02:33:45
问题 I have a observable collection that binds to a data grid. I also have in the view model a color property and I want to bind the background of each row in the data grid to the color property on the vm. 回答1: You can bind the Background in the RowStyle for DataGrid <DataGrid ...> <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <Setter Property="Background" Value="{Binding MyBackground}"/> </Style> </DataGrid.RowStyle> <!-- ... --> </DataGrid> This will work if MyBackground is a Brush . You

WPF4 DataGridHeaderBorder in a xaml Style

ⅰ亾dé卋堺 提交于 2019-11-28 02:16:55
Making a separate question, related to comments on the answer to WPF 4: What happened to DataGridColumnHeader? It appears I can use DataGridHeaderBorder in a UserControl, stand-alone in a ResourceDictionary, but not in a Style's setter of a Template. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <!-- Works --> <DataTemplate x:Key="yomama"> <DataGridColumnHeader /> </DataTemplate> <!-- Compile Error: error MC3074: The tag 'DataGridHeaderBorder' does not exist in XML namespace 'http://schemas

Date Converter using WPF

对着背影说爱祢 提交于 2019-11-28 01:26:46
问题 public class DateTimeConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values != null) { DateTime test = (DateTime) value ; string date = test.ToString("d/M/yyyy"); return (date); } return string.Empty; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); }

WPF DataGrid 'Refresh' is not allowed during an AddNew or EditItem transaction mvvm

烈酒焚心 提交于 2019-11-28 00:15:20
问题 I have the following grid <DataGrid x:Name="TablesDataGrid" Grid.Column="0" Grid.Row="1" ItemsSource="{Binding FilteredModels.View}" AlternationCount="2" AutoGenerateColumns="False" CanUserSortColumns="True" CanUserReorderColumns="False" CanUserDeleteRows="False" CanUserAddRows="False" SelectionMode="Extended" IsReadOnly="False" SelectionUnit="FullRow" RowHeight="25" HorizontalAlignment="Stretch" ColumnWidth="Auto"> <DataGrid.Columns > <DataGridCheckBoxColumn Width="*" Binding="{Binding

Datagrid Column header should check / uncheck CheckBox’s state depending upon whether all CheckBoxes of a DataGridView column are checked or unchecked

那年仲夏 提交于 2019-11-27 23:06:53
The problem i'm stuck with is related to checkbox in DataGrid(WPF). I've attached the screenshot for better understanding of the problem. Problem: The DataHeader Column Checkbox is checked even when one of the child is Unchecked. I expect the solution to fix this so that when one of the child is unchecked explicitly by the user, The ALL(Column Header) should be unchecked implicitly. Please help guys... Thank You Plz check the link. i want the solution to work like this. http://www.codeproject.com/Articles/42437/Toggling-the-States-of-all-CheckBoxes-Inside-a-Dat# <dg:DataGrid.Columns> <dg

filter wpf datagrid values from a textbox

夙愿已清 提交于 2019-11-27 21:38:19
I have a textbox and a Datagrid. The datagrid has two columns name and Email address. I want to Filter the datagrid values with the value in the textbox. You can use a ICollectionView for the DataGrid ItemSource then you can apply a Filter predicate and refesh the list when needed. Here is a very quick example. Xaml: <Window x:Class="WpfApplication10.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="188" Width="288" Name="UI" > <StackPanel DataContext="{Binding ElementName=UI}">

wpf datagrid alternate row coloring

自作多情 提交于 2019-11-27 19:59:11
I have tried this method.. without luck.. <Style TargetType="{x:Type DataGridRow}"> <Style.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Foreground" Value="Red" /> </Trigger> </Style.Triggers> </Style> Is there a way to get the row Index? I have even tried <DataTrigger Binding="{Binding AlternationIndex}" Value="0"> <Setter Property="Foreground" Value="Green"></Setter> </DataTrigger> Unless already done, you have to set the AlternationCount property of DataGrid: <DataGrid AlternationCount="2" ... /> You should additionally check whether the Foreground