wpfdatagrid

Wpf DataGrid issue

与世无争的帅哥 提交于 2019-12-10 13:00:05
问题 To reproduce this issue, Add a user control, paste in the xaml below and then add an instance to a window. Finally set the window's datacontext to an instance of ADummyDataContext (also below) When you run the application for the first time, you should get a grid with three categories each containing one cat. If you click on either of the bottom two categories and click on a cat name, a blue row will appear showing just the cat's name. However, if you click the first row and click the cat's

How to simulate the user click on a column header of a datagrid in WPF?

不羁岁月 提交于 2019-12-10 11:48:59
问题 I need to simulate thru code the user clicking on a header of a WPF datagrid column (using .Net 4 in case it matters). Is this possible? 回答1: I think you can use the AutomationPeer classes, which are designed for this sort of thing, specifically the DataGridColumnHeaderItemAutomationPeer Class. DataGridColumnHeaderItemAutomationPeer peer = new DataGridColumnHeaderItemAutomationPeer (Your_control); IInvokeProvider invoker= (IInvokeProvider)peer; invoker.Invoke(); // Invoke a click

How to export PDF from data of datagrid?

末鹿安然 提交于 2019-12-10 10:59:42
问题 How can I export the data from DataGrid into PDF? The quick solution. <DataGrid Name="table" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" IsTextSearchEnabled="True" Background="White"> <DataGrid.Columns> <DataGridTextColumn Header="Timestamp" Binding="{Binding StartDate}" SortDirection="Descending" SortMemberPath="StartDate" IsReadOnly="True" /> <DataGridTextColumn Header="Title" Binding="{Binding Title}" IsReadOnly="True" /> <DataGridTextColumn Header=

Conditional Formatting of WPF DataGrid Cell Depending on DataType

偶尔善良 提交于 2019-12-10 10:54:37
问题 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"

WPF and entity Framework code first

北慕城南 提交于 2019-12-10 09:56:38
问题 I would like to implement a simple WPF with a datagrid and a save button. when I click save button it will accept changes (row edit,cell edit, new row, delete etc) I tried RowEditHandler and CollectionChange event using observable collections. But I couldnt get a soluton. Can anyone please show me a simple way. Using dataset (xsd), I was able to achive that simpy by sending datacontext of grid to dataset and using update function. thanks for help 回答1: The ADO.NET team blog has an example how

Cannot create an instance of “MainViewModel”

百般思念 提交于 2019-12-10 06:03:13
问题 I am creating a simple WPFapplication for implementing Databinding a Datagrid to database using Observable collection (following MVVM pattern). App.xaml.cs class public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var mainWindow = new MainWindow(); var viewModel = new MainViewModel(); mainWindow.Show(); } } when I try to bind it to my XAML I have the following error raised : Cannnot create an instance of "MainViewModel" XAML code

WPF DataGrid AlternatingRowBackground and RowStyle precedence

寵の児 提交于 2019-12-10 02:47:24
问题 How do I make my RowStyle to get applied after AlternatingRowBackground ? I want items, having IsOrange as true to have Orange background regardless of alternating row background, which isn't the case currently. XAML: <DataGrid Name="g" AlternatingRowBackground="Blue" AlternationCount="2" ... SelectionMode="Single"> <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <Style.Triggers> <DataTrigger Binding="{Binding IsOrange}" Value="Y"> <Setter Property="Background" Value="Orange" /> <

WPF DataGrid not updating on PropertyChanged

て烟熏妆下的殇ゞ 提交于 2019-12-10 01:52:41
问题 i've a problem updating my datagrid when clicking the button by using NotifyPropertyChanged. It works if i set the DataGrid.ItemsSource in code behind, but it doesn't if i set it in xaml. here's some code of code behind & xaml: namespace MyWpfDataBindingLab { public partial class NpcWindow : Window { DataCollection dc = new DataCollection(); public NpcWindow() { InitializeComponent(); //command binding code //... } private void Window_Loaded(object sender, RoutedEventArgs e) { //if i set the

WPF DataGridTextColumn multi-line input

家住魔仙堡 提交于 2019-12-10 01:10:22
问题 I am using the WPF DataGrid control in .NET 4 that have a DataGridTextColumn. I want to be able to enter multi-line text. The line breaks are formatted correctly when I bind data to the column, but I've found no way of creating the line breaks when editing the text. <DataGrid ItemsSource="{Binding MyMessages}"> <DataGrid.Columns> <DataGridTextColumn Header="Message" Binding="{Binding Path=Message}" Width="Auto"/> <DataGrid.Columns> </DataGrid> Any suggestions? 回答1: Try: <DataGridTextColumn

Change the position of the scrollbar in a WPF Datagrid

孤街醉人 提交于 2019-12-09 22:56:34
问题 I have a layout problem with a datagrid in my C# WPF application. If the content of my datagrid can't be displayed in my datagrid because there are to many rows, a scrollviewer (and scrollbar) is displayed. This is the correct way and I'm happy about it. The problem is, that the position of the scrollviewer in my datagrid ist wrong. The scrollviewer starts in the header row, but the Scrollbar is displayed in the first row of my content. In the header there is a white retangle. This is because