wpf listview changing selected item display behavior - wpf

I want to change the display behavior of the selected item(s) in a WPF Listview. Specifically, I want to retain the custom textblock foreground colors that I've applied and apply a border around the item.
I am able to alter SystemColors.HighlightBrushKey and ControlBrushKey to change the background color of the selected item, but I don't know how to get it to stop changing the font color or use a border instead. I've tried manipulating the control template and have also searched Google for examples of how to do this, without success.

yeah, looks like you have to go through the pain of using ControlTemplates.
Good news is that via using Expression Blend, you can get current ControlTemplate for ListView and tweak the bit that you need and use that as your default ControlTemplate.

Related

Datagrid Colors

I make my own style for datagrid, I had changed every thing but there's a small part of datagrid make me crazy, because I can't change color for this part. I don't know the name of this part, as showing in the image :
How can I change color it?
It's not so clear from your image, but if that part is part of the ScrollBar then you can add a Style without defining an x:Key for it into your DataGrid.Resources section. That way, it can be implicitly applied to the ScrollBar parts. You can start with the default Style and then adjust it for your needs. You can find the default Style in the ScrollBar Styles and Templates page on MSDN. There is quite a lot of it so you'll have to do some experimentation with it.
UPDATE >>>
If you are talking about the Buttons that you can click to select the row, I believe that that part is called the row header. You can add a Style for that using the RowHeaderStyle property. Please see the WPF override DataGrid RowHeader template and manage to select rows still post for help with that.
Alternatively, I believe that you can hide it altogether by setting the DataGrid.RowHeaderWidth property to 0.

How to get an existing property from style

I'm developing a WPF project where I need to validate textboxes on code-behind and then change the border color of those textboxes to some unknown color defined by the user configuration; the problem is that to overwrite the MouseOver effect I would need to set the value from XAML directly via ControlTemplate or Style.
Is there a way to get the current value assigned to the TextBox from XAML? Maybe binding it to itself?
I will appreciate any help you can give.
When validating a TextBox, or any control for that matter, it's common to use an adorner to display the validation error (in your case, setting the border color). You can have a look at an example here.
Using this method, you don't actually change the TextBox's border, but create a new visual layer on top of the TextBox that draws the new border around it. This is pretty much the way validations should be done in WPF, and it also solves your problem of having to deal with changing the TextBox's border value back and forth.

Change foreground/background color of Item in Listbox programmatically in WPF

How can i add different items with either background/foreground color different in WPF listbox?
You can can create a DataTemplete, set it to ListBox.ItemTemplate and use DataTrigger to change the display of the items.
ListBox has some very annoying behaviors that make styling it using data template difficult - in this blog post you will find the list of workarounds.
You may use an AlternationCount property, more info provided by this link
Or you can add to your objs binded to a listbox Background and Foreground properties and bind them in a DataTemplate of ListBox.ItemTemplate and change them in code however you like, properties must update themselves on every changing.
After tearing my hair out with this one (and your particular usecase might differ from mine) I found the WPF Toolkit's DataGrid cured all my needs.

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.

Silverlight: Setting ComboBox Background-Color Programmatically

This seems like it's far more difficult than it should be, but I'd like to set the background color of a dropdown combobox programmatically (ie. if the user selects one value, I'd like it to appear red, otherwise blue...)
What I've noticed is that if you just set the Background property to a SolidColorBrush, the only thing that seems to change is that slight-glow that the ComboBox has.
I know that the ComboBox is constructed of multiple objects, and that it takes more than just setting the BackgroundColor, but I'm just wondering if there's a simple way of doing this programatically, where the entire background changes colors, instead of the glow.
Unfortunately most of the colors involved are hardcoded into the combox style. Hence the only way you are going to achieve greater control over the color used is to copy out the entire ComboBox style and simplify the set of Rectangle elements named Background.....

Resources