Datagrid Multiple row selection style - wpf

I have this task where the datagrid allows selecting multiple rows. When single row is selection, its style is to show 1px border around that row. Now when multiple row is selected, it should show a 1pm blue border around all the rows as a single block. So its like a box around all selected rows. Not each rows having its own border. How can I style this ?

I did something similar before. You can use DataGrid.ItemContainerStyle for the purpose.
You can style the ControlTemplate property for the DataGridRow (which is the type of the item container), study this blog on how to do that. In the template you should include a new Border.
The IsSelected property of the DataGridRow should be bound to some property of the model (data of the row) which can notify the viewmodel or whatever service you use to collect the selected rows. The Border which is included in the ControlTemplate should bind its StrokeThickness to the same viewmodel or service. Then you can use a Converter on that binding which uses the viewmodel or service to figure out which side of the border should be thick for that specific row.
This task is not easy, but possible. You might face some architectural challenges. I would use MVVM, DI and other patterns in order to avoid chaos.
I hope it helps.

Related

Silverlight datagrid template column

I'm fairly new to Silverligt 5 and xaml for that matter and I have come across a problem. I have a datagrid containing a template column. This template consists in a bunch of TextBlocks, images and other controls. I've customized the way the grid looks by overriding the grid/row/cell style using the VisualStateManager. Everything works fine when changing for instance the row background and borders on MouseOver. However I didn't find a way to change the foreground color of just one of the TextBlocks in the column template. So I'm not trying to set the foreground of the cell it self but only for one of the many controls(a TextBlock) in the column template. When the user is hovering a grid row, I want - apart from changing the background of the entire row, to also change the foreground color of this particular TextBlock.
Hope this makes sense
You need define style for DataGridColumnHeader Template
look here : MSDN

How can I apply AutoGenerateColumn to apply DataGridTemplateColumn.HeaderTemplate in a DataGrid?

for an overview, an MVVM project in built in WPF.
Basically in my xaml, I have a datagrid bound to a dataview. When my service populates the dataview I get a dynamic table with an arbitrary number of columns.
For each column in the datagrid, I have created a headertemplate which contains a combobox which is bound to an Observable<Dictionary<string,BusinessEntity>> object as its item source in the xaml. Figuring out the combobox is another issue but I am trying to just populate data grid first, then worry about binding the combobox correctly.
anyways the only solution I have somewhat though of was to turn on autogeneratecolumn and then replacing all the headers with a combobox in the codebehind, but then I have issues trying to bind the combobox in the codebehind correctly and it doesn't feel MVVM if I have to create all those comboboxes there.
You can handle the AutoGeneratingColumn event to customize the auto generated column's header template.

Silverlight Textblock set lines

I have to develop a control having one datagrid. now datagridtextcolumn have to be binded with one property of collection created in viewmodel.
based on data i have do one thing...
if for a row no of lines is more than 3 in last column's cell then show a button having text "More" with last cell else with text "Less" and on click of "More" button it should display full text data...
now this layout can be shrined as well as stretched at runtime according to window's height and width using viewbox control or any other way...
so how to achieve this thing any idea???
Basically you want a custom textblock control that displays a max of 3 lines and shows a more button (if there are more than 3 lines of text)*.
The more button expands the textblock and I imagine stays around to collapse it again?
As it sounds like you only have one column (more like a list), rather than customise the datagrid create a usercontrol (with a grid, textblock and button) that does what you want and bind that inside a templated column instead.
You will need to expose the Text property as a dependency property for it to bind to. Most of the details of creating this type of usercontrol are on my answer to this: putting Button inside a TextBlock(or maybe something else) to make it work like the one on video?
Just add your size logic and change the layout to suit your needs.
*Note: Personally I would use the MinHeight property of the usercontrol to set when the "More" button is needed, then it will be more flexible, but that is just a suggestion.

Listbox styling and control template issue in silverlight

I have to change Listbox's control templated in a way that it can look like below image
alt text http://www.freeimagehosting.net/uploads/05598e4d35.png
i have added togglebutton in listboxdatatemplate...
have one stackpanel in listbox style template...
so structure is like
border - stackpanel - grid - itemcontainer[boder-togglerbutton]
now to make first and last item curved... what are the ways...
if i make stackpanel border curved... when firstitem is selected and its background is changed... it shows a square inside outer border... so i am not able to get look showed below...
any idea?? how to get design done in the way with listbox tht can be showed like image above...
in image 1,3 and 4 items are selected and others are in normal mode...
-thanks in advance
I did it with a listbox in Blend inside of the ItemTemplate by creating a leftBorder and a right Border that are in the same space. The leftBorder is defined with cornerRadius 10,0,0,10 and the right with cornerRadius 0,10,10,0. I then set them both to opacity 0 (you can use visibility if you prefer) and set a ChangePropertyAction on both of thier loaded events conditional on the first and last item in your list.
That is the bad part, I did need to do it conditional on the items in your list but you could define another property and set that to first and last or create multiple templates that you set if there are no more items in the list from the control (not in the template).
If you think this may be interesting to you, let me know and I will post on my blog as well as try to make a couple of adjustments for your situation. I am not sure how to upload a project to here.

Sliding effect when adding new items to a WPF ListBox

I have a WPF ListBox control which displays items of an RSS feed. I occasionally check the source of the RSS feed for new items. Once I detect a new item I add it to the observable collection which immediately adds the new item to the ListBox display.
Is there a way to 'slide in' the new item from the top, pushing down the existing items? How would I achieve such an effect? Can it be done with a ListBox, or do I need to resort to my own container, such as a StackPanel and animate for example the Height of newly added controls programmatically?
I just posted an answer to this question which is very similar to yours.
WPF how to animate a list of components
It can be done with a ListBox. Use the ItemContainerStyle to style the ListBoxItems that the binding creates for you: this style can include animations, e.g. by adding an EventTrigger for the Loaded event to the Style.Triggers, and transforms. For example, in your trigger action you could animate the Height so the item expands into place, or if the height is unknown you could have your style set a ScaleTransform and in your trigger action animate the ScaleY of that transform from 0 to 1.

Resources