WPF Style Trigger - wpf

I am trying to get a row in a datagrid to turn red if the value of a checkbox within the datagrid is true. Any ideas? Here is what I have so far. I am currently turning the columns red if the mouse rolls over the row.

Take a look at this blog post by Vincent Sibal. Sibal gives several code examples of what you're trying to do and he also provides a good sample project you can download to see the source.

Related

How to use a control equivalent to the WinForms DataGridView in WPF

I've been creating an inspection form using WPF and I need a place where users can type an unknown amount of comments (hence why I'm not using textboxes). In my WinForms version of this application, I used a DataGridView and I could enter in as much information as I wanted to. I'm looking to do the same with a DataGrid or an equivalent control in WPF.
WinForms Example
I need to be able to do the same thing in WPF but I can't seem to add any rows in the DataGrid. On top of that, when I try to check CanUserAddRows it unchecks it immediatly.
So I checked out Vincent Sigal's blog post about this issue. He mentions something interesting:
... but beware of CanUserAddRows and CanUserDeleteRows as they can appear a little magical. Their values are coerced based on other properties such as DataGrid.IsReadOnly, DataGrid.IsEnabled, IEditableCollectionView.CanAddNew, and IEditableCollectionView.CanRemove. So this is another thing to watch out for when editing. If you run into a situation where you set CanUserAddRows or CanUserDeleteRows to true but it is changed to false automatically, check that the conditions below are met.
I verified this and my DataGrid is not read-only and it is enabled. Although, I have no idea where to find the IEditableCollectionView.CanAddNew and IEditableCollectionView.CanRemove ...
I don't think my situation should require a binding event on the DataGrid since the user is supposed to enter his comments directly into the DataGrid ... Is what I'm trying to do even possible? Perhaps I should use a different control?
I have to admit that I stopped reading through your question after the first paragraph, so please forgive me if I have understood you wrong... but if you just want to enter multi line text into a TextBox in WPF, you can do it by setting a couple of properties on it:
<TextBox TextWrapping="Wrap" AcceptsReturn="True" />
For a DataGrid, you can set these properties in the DataGridTextColumn.ElementStyle and/or DataGridTextColumn.EditingElementStyle as the WPF DataGridTextColumn multi-line input post shows quite nicely.
Please let me know if I did misunderstand you.
UPDATE >>>
Ok, so I came back to read the rest of your question... answering without reading the question can be risky business on this site. It's just as well that I did too, as I see you also want to know how to use the DataGrid.
I have to start by saying... take a deep breath... WPF is very different to WinForms... very different. In WPF we manipulate data rather than UI objects, so to add a new row actually means adding a new item to a collection. You can find a complete working example on the DataGrid Class page on MSDN.
Please also view the WPF DataGrid Control page on WPF Tutorial.NET for more examples. WPF has a lot to take in for new comers and can be quite bewildering, but it's well worth the trouble when you get into it.

Check Combo Box in DataGridView in Winforms

I'm searching awhile for CheckComboBox column for DataGridView in winforms, without any result. Is there written classes that implement such things (freely) in the web? I've found some other custom columns and I've found CheckComboBox implementation, but I failed to connect them together and to make them work properly... :( Thanks.
I dont think you'll be able to find one because a CheckBoxComboBox isn't very common, but you can write one yourself. Here is an example of a Custom CheckedListBoxColumn to get you started.
If you get stuck follow this article that takes you through the process Create a Custom DataGridView Column.

DevExpress GridControl ColumnAutoWidth

The question is probably silly, but I spent half of the day looking for the answer with no luck.
I have a WPF view with DevExpress GridControl included (not developed by me). The problem is that when I click "Auto fit" option - it gets too wide with a horizontal scroll. The reason is long header titles, but it's Ok if they are wrapped into 2 lines.
After some searching, I thought that what I need is ColumnAutoWidth property. The problem (here goes the silly part) is that I can't find out how to set it! Because of this I can't check if it works at least! There are no examples in documentation, and code autocomplete doesn't show it's presence anywhere. I had some assumptions but they appeared to be wrong.
Can somebody please share XAML (or at least code-behind) example about how to access this property?
you just have to remove width element from your columns, and to set the autowidth element of the tableview. the link you posted is related xtraGrid control and it is a windows form not a WPF one, you have to control the width from the TableView.AutoWidth property.
Try to read the following documentation
Your link is documentaion for WinForms grid. For Wpf GridColumn http://documentation.devexpress.com/#WPF/DevExpressXpfGridGridColumnMembersTopicAll
As I understand you question - you want to fix column width. Try this
<dxg:GridColumn Header="MyAwesomeColumn"
Width="40"
FixedWidth="True"
FieldName="MyFieldName" />

Visual Studio 2010 listbox with detail

I've not been doing much WinForms programming for the last few years, so I'm a bit rusty. Right now I'm having trouble with something pretty simple. I have one table of data that includes two foreign keys to two other tables. What I want to do is simply display a list box that shows a name field from the table and several text boxes below, which display the rest of the data in the row corresponding to what is selected in the listbox.
I tried simply setting the datasource on the listbox and then binding the detail textboxes to columns in the same datasource (using bindingsource), and that seemed to work fine. However, when setting the comboboxes up for the two foreign key columns, they did not reliably change to display the correct value as the user selected different items in the listbox. Additionally, when I made any changes in the detail textboxes, the HasChanges method on the dataset still returned false.
What do I need to do to get this to work correctly? Is there a good example out there somewhere? Google just seems to return a ton of results showing how to populate a simple listbox.
I saw this had been up for a few days so I'll provide what help I can...
I'm a bit rusty in that area as well. However, the place I always go back to for a refresher is the Forms over Data Video Series by Beth Massi. They are short, sweet and to the point. My guess is that you'll find what you need within the first few videos.
Disclaimer: The videos were done using VS2005. The fundamentals are solid though. While one or two minor things may have changed, WinForms databinding is pretty much the same as it has been for a while.
HTH and good luck!

WPF Combobox bug when form allowtransparency=true

I have found the following in WPF:
I have a form with AllowTransparency=true. Inside the form I put a Combobox.
I add some items to the combobox.
I run this application and click on the combobox. At first it does not seem to appear at all. On closer inspection (after adding more items) I see that it is actually appearing behind the form. If I add enough items it become visible from behind the form.
If I just change AllowTransparency=false, then all is fine.
This looks like a bug in WPF (3.5 SP1).
Any one know of a workaround for this?
Go to
https://connect.microsoft.com/dashboard/?wa=wsignin1.0
submit your feedback after searching #
https://connect.microsoft.com/VisualStudio
https://connect.microsoft.com/VisualStudio/feedback/CreateFeedbackForm.aspx?FeedbackFormConfigurationID=1160&FeedbackType=1
and mention steps to reproduce.
There was an update of 3.5sp1 but you could test,but I doubt
http://www.microsoft.com/downloads/details.aspx?familyid=6c095bba-6100-4ec9-9c54-6450b0212565&displaylang=en
AllowTransparency is slow and buggy and shouldn't be used - it's a great way to run into bug in various display drivers.
You can get almost anything you like without using AllowTrasparency, take a look at this post for examples:
http://blogs.msdn.com/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx

Resources