Reset buttons images on WinForms - winforms

The button's images are binded to the resource, like this:
btnCancel.BackgroundImage = Localization.Labels.cancel;
And depending on culture desired image is selected. But culture could be changed while runtime and button's images should be reseted depending on new selected culture.
Of cause I could just copy the same like of code in redraw method, but there are lots of controls, and I'm looking for more elegant way.

Related

Why may setting Image or BackgroundImage have no effect?

I'm trying to figure out why setting a control's Image property on one form has no visible effect, while setting the same property of a control that belongs to a different Form works perfectly. My target form has non-default background color (it's all black with a white foreground color) and no border style. Setting the other form to the same color and border style does not affect its ability to display images. So what's wrong with my target form? What settings could I have tripped that make my image sets do nothing?
Turns out the problem was that I was initializing the form from within itself, so it had no suitable graphics context to give itself to display images on. Moving the form's field outside its own class to the main form solved the problem.

WPF - datagrid adorner not updating upon binded PropertyChanged

I am using a solution found here: http://malor.se/blog/?p=88 to add adorners to a datagrid text column. Works fine, except my adorner is binded to the underlying object, and it's failing to update upon source property changes. I can even bind the cell contents and the adorner text to the same property, and the cell content will reflect property changes while the adorner text doesn't. The adorner seems to refresh only when I do something to force a redraw of the cell, like resizing the column.
Is there a fairly non-hackish way I can get the adorner to refresh upon source property changes like other normal wpf controls?
Web searching seems to indicate that the adorner layer refreshes only on certain events, like a resizing, for the sake of performance I suppose. I'm now of the opinion that maybe it's not the best choice for my particular task.

Locking controls on the canvas in a form editor in WPF

I am building a form editor in WPF. One of the features we need in it is to let the user "lock" one or more controls on the canvas. By locking I mean the user would not be able to move, resize or modify other properties of the control.
I have tried with ContentControl but did not get the results I am looking for.
I think you should use the IsEnabled property. Basic controls with interaction have this, and you can expose it on your custom controls as well and pass the property down.
If something is set with IsEnabled = false it will be grayed out and cannot be affected by user input.

Image Button with no border that works like a toolbar button?

I want a button that
Displays an image with NO border, NO background, NO text
If I tab into the imagebutton, THEN it shows the background and border
Also if I hover over it, it shows the background and border
I've searched and I've tried so many different things, but nothing it exactly what I want. I've tried setting various properties on the button to make the background and border transparent, but it still shows up. I've tried a style with a custom control template. I'd rather not have to completely reinvent all the triggers etc to get the button to render on mouse over. The biggest problem with custom control template is that then I loose all existing functionality and I'm basically building a new control from the ground up.
Here is another link that came closest to what I wanted but it doesn't properly work for me.
How do you completely remove the button border in wpf? - BUT.... for some reason the hover effect gets stuck. One I mouse over the image and the button border draws, it stays stuck on until I click somewhere else.
Actually, you will want to override the control template. You're not "losing" any functionality (aside from the UI triggers).
Original/Default Template -- This is a good starting point... copy/paste that into you're XAML (wherever you want to style this button... ie Button resources, UserControl/Window resources, App Resources?). From there make your adjustments.
Another easy way is to use Expression Blend. You can easily create a new template based on the existing template, and the styling/authoring tools it provides are much better than hand-coding XAML (unless you're good at doing that).
As far as displaying an image instead of text, just set the image as the content. A Button is a type of ContentControl which means that it can house any type of content (Object).

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