VisualStateManager: How to make the 'current' color lighter in MouseOver? - silverlight

1) Imagine a DataGridColumnHeader control is meant to be in Green color by default.
2) If I click on it, it would activate the Sorting to "Sorted Ascending", this is when it should become Orange. Clicking again on it would change it to "Sorted Descending", which still should remain in Orange color.
The two cases above are easy to do with VSM. However the following two scenarios seem to me impossible without a Multi-trigger (which we dont have in Silverlight)
1b) Whenever I hover with the mouse over the non-sorted control, it should become light green.
I hover away, it should go back to base green.
2b) Whenever I hover with the mouse over the sorted control, it should become light orange.
I hover away, it should go back to base Orange.
How should I determine within
MouseOver state, in which mode sorted
state is, in order to choose light
orange or light green accordingly?
Alternatively is it possible to
lighten the current color up, without
knowing what color it actually is?

The easiest would probably be to just make the opacity lower when mouse over, effectively making both green and orange lighter.
Or alternatively you could create a visual state group for sorted states, set it with a data trigger and change the colour of the mouse over element accordingly.

Related

Ellipse as mask for a label

I'm making a toggle button with a new design "material design" like. I have a problem with animation. I'm using an ellipse that expands and changes the color of the button where the mouse clicked. With color it works well but I want to make visible label as ellipse is over it and invisible the second one. I have an image to make it simplier to understand:
so the second image shows that where the green is it stills writes "Toggled" where it should already write "Untoggled" but still where blue color is, there should be writed "Toggled" then radialy changes. I have tried to use Opacity Mask but I couldn't get it to work. Anyone could help me?
Ok I did it animating EllipseGeometry, settings the label I want to display on top of the old one and clipping the top one to the EllipseGeometry.

What causes colour discrepancies on borders after scrolling?

We noticed some weird behaviour in our WPF application.
We have a customised, expander like UserControl, which has a Border around it - we'll call it expander. There can be several of these expanders in a view, which means scrolling is needed. When an expander is scrolled out of view, and back again, the border sometimes changes colour. Not every time, and not consistantly. For example, the lower border can be slighly lighter in colour, while the right border can be darker, even though they use the same brush. The next time it's scrolled out of view, and back again, the colours can be back to normal.
It almost looks like a scaling/antialiasing effect. Has anyone else seen this behaviour, and is there anything we can do about it?
To complicate things a bit - but only a bit - the expanders are children of a ListView. This is because we want to emulate HTML anchoring, so we externally can jump directly to a given expander. Could this be part of the problem?
This seems to be a anti-aliasing issue, as explained here and here.

Silverlight 4: how to highlight control on mouse over

My aim is to get fine control "animation" when it is mouse-over-ed. For example, I have a "map" of controls (game map that represent different type of terrain), each of them is an image with trees/rocks/hills on the green grass or water (lake or see) image of blue/cyan color. When user point any image with mouse it should get shiny: either get more bright background or get a shiny border.
It is hard to say what exactly I want to have (either background change or border), I would like to try each of them and see what is the most appropriate for me.
I am going to have a custom control (MapTile) that will represent a map tile. I know how to catch MouseEnter/MouseLeave events, but not sure how to change control style and if it is a good idea to work with control style in CodeBehind, probably there are better XAML-based solutions.
Could you please help with a solution that provide few goals:
Goal1: Add highlighted border around the control (it will be squares/rectangles, or circles; use what is easier) on mouse enter, remove border on move leave;
Goal2: Change some properties of my CustomControl (for example, background color).
Thank you very much!
1. How to han
You might find it easiest to get hold of Expression Blend and use it to create a custom template for your control.
The Learn Expression Blend page would be a good place to start. Look for tutorials on customising buttons and this is the same sort of thing that you want to do.
You need to use an attached behavior on your control. You don't need to learn Blend for this.
Check this one as an example, but you can search the site for Mouse Over for other examples.
http://gallery.expression.microsoft.com/en-us/MouseOver3D

WPF: Changing the look of a Surface Listbox "click-effect"

I'm changing the look of some Controls that I use in my Microsoft Surface Application at the moment. And today I'm working on a SurfaceListBox.
I have the template for it and already changed background and borders and other stuff.
But I really cannot find where I can change the color of the rectangle that appears on the ListBoxItem when you touch the ListBox. At the moment it's just white and I want to change that.
It's not something like the effect that you can see when the item is selected. I already found that and changed that so my selected item now appears in a different color. But the effect in the second when you touch the item stays white.
So where can I change this effect?
If you mean the bright, white highlight that happens when you press your finger against an item you should look into the SurfaceShadowChrome. It's used by (almost) all surface controls to give feedback when the user is pressing on a control.
It does have a Color property that you can modify to suit your needs. Apart from the color, and the tweaking of corner radius and shadow offset, it's not a very flexible decorator. But hopefully, you'll be able to make it do what you need.

WPF Custom Draw Multiple Progress Bar

In processing a group of items, I wanted to display a unified image of the status of the group, so I essentially made a Grid of a number of progressbars with transparent backgrounds and various colored foregrounds all at the same cell.
I'm running into some transparency artifacts (purple bar is actually purple under the green, and sometimes it draws over the top, etc) and it just seems a bit wasteful. So, I decided to make my own, but now I've got a bit of paralysis on how to do it. Do I use the DrawingContext in FrameworkElement's OnRender, or is there something simpler? Is there a set of general rules when it comes to making your own control?
I pondered switching to a pie chart since those are easy to come by, but its high time I did something not off-the-shelf.
Thanks!
I'm not quite sure how you intend the progressbar to combine different progresses, but if say the furthest along progress is at the bottom of the z-index and the least along progress is at the top, then I'd do something on the lines of this:
1) I would probably create a user control for this new progresbar.
2) It would have a property called NumberOfProgresses, that is tied with an array containing status of said progresses.
3) Each progress would be represented by a Border item (or perhaps something more suitable up the visual tree), because it's a simple wpf control with a background property. The background property would be set to nice a looking progress style and the progress color can be bound in the style to say the border's borderbrush property. Making it easy to set the color of the progress.
4) The user control would have a method UpdateProgress which takes the percentage value and the index of the progress in the array as parameters.
5) As progresses are updated you can either, just calculate the appropriate width (user control actual width * percentage) for the border and play around with the Z index to get it displayed at the top/bottom, or stack the borders horizontaly, set the least along progress as first, then for the rest of the progresses you'd have to substract previous progresses lengths to get the same effect.
This way there would be no transparency induced artifacts and no OnRender()...
Mind you, in WPF there should be no reason to mess with OnRender this and OnRender that, like it was required in WinForms with OnPaint.
Just set up the elements via code to get the look you want, and let WPF do it's rendering ;)
I can imagine one problem with this user control though. You'd have to provide feedback to the user as to which color belongs to which progress. But that would probably take you back to square one, meaning it's better/simpler to just display multiple progressbars.

Resources