WPF DataGrid with selectable rows and button
Hello all,
I am new to C# but purchased Linqpad to try and learn some new skills, and have to an extent cutting and pasting and meddling from the internet.
I have managed to get my results from my Gmail API query into a list of class objects, but would like to have them in a WPF DataGrid with a button that I can use the selected rows from the results by CTRL left clicking to select, then do something with the selected items.
Could someone please give me a small example of this? I am going in circles and seem to have fallen into some ""double quote"" syntax hell with the XAML.
The resulting use will be to mark the selected Gmail emails as read.
Thanks for looking.
Comments
Can you post what you have so far? The whole file contents or a link to it hosted somewhere like github.com. Remove any confidential info.
I forgot you can use the Instant Share feature.
@stephensmitchell
With regard to WPF DataGrid , I do not have anything, I have tried to create XAML file in Visual Studio then import or create a string of XAML for XamlReader but am missing something about escaping double quotes. Just a basic example from a List of classes to WPF DataGrid would suffice.
Thanks
I think if you import the .xaml file from a stream:
This will properly escape quotes.
Ah ok thanks, I will try this, I had been trying to use System.Windows.Markup.XamlReader.Parse
I cant seem to get my stupid head around this , I have managed to get some output , but doesn't seem to respect the XAML string for coloring alternate rows . I have up loaded what I have working so far. I have no idea how to the get the msgIDs for only the selected rows I click on to work with later on.
This XAML stuff is too complicated for me , can I do this directly in some Linqpad utility?
anyway this is what I have so far , mostly cut and paste from the internet
http://share.linqpad.net/mrmbqn.linq
Me too. I have only ever done the very basic, like changing the colour of the Alternating Row, which on the dataGrid I would use
To get the selected items, you can iterate through list.SelectedItems
Working with XAML in code is error-prone, and harder to update without Visual Studio XAML tools. The purpose of my filestream post was to suggest loading all the XAML from a file to then use in LINQPad. It's easier for
me to use only code for WPF in LINQPad rather than working with XAML as a string otherwise I use Visual Studio.
I attached a quick concept of how I build WPF tools without XAML. This is a simple example not sure what your end goal is but here is something.
This is VB code, but it should be easily converted to C# (https://converter.telerik.com/). Most of the code is one-to-one with C#.
http://share.linqpad.net/lwv4lv.linq
@sgmoore
Wow thanks so much, thats working now, so simple when you know how, I have been banging my head with all this XAML syntax hell, I thought I had to use XAML to create my DataGrid and buttons.
@stephensmitchell
Thanks for your help your example is great, I haven't looked at VB for years. I did try what you said regarding file stream, I had a working Xaml file in Visual Studio but when importing it had a lot Xamlreader parser errors , even though it compiled and ran in VS.
Thanks again to all