Editing background of a template on the story board during an event trigger turns background black - expression-blend

So, I am having an odd behavior. Maybe it's intentional, but I can't seem to figure it out. I haven't worked much in Blend and prior to this been mostly coding XAML manually. I am trying create a custom template for a MenuItem and when it's being moused over, I need to turn its background a specific color. So, I'm doing this MouseEnter event trigger on the OuterBorder. When I try to change the color, no matter what color I set it as, it turns black immediately. This happens on all of the control in template, regardless which one I choose. So, I have to manually go into XAML and change it to the specific color.
After I set it to a specific color within the XAML code, if I try to change it through the Properties menu, it'll turn back to that color I set in the code.
If I export template into a ResourceDictionary, it lets me edit everything as if nothing wrong is occurring, but when the template is applied, the default background of the MenuItem control turns black.
By the way, this is Blend for Visual Studio 2013.
Any ideas what's going on?
What I ended up doing was not creating a separate even trigger and instead edited the template's existent triggers. Which worked great. My only concern is that the default one did not do fill, so I fail to see how there was a conflict between the two. Not sure if anyone knows?

Figured it out. Silly me. I was trying to change background that didn't exist. So, it had to create the background for the storyboard, and thus was setting it as the default black. What I did was create a background and set it's opacity to 0% and then change that instead. Worked as intended.

Related

Event for Markup drawing

What is the name of event when we start drawing the markup(circle, arrow, rectangle etc.) on the shape when in edit mode? And can we change the markup type in this event?
Problem is: When we are in edit mode and have selected specific shape and color to draw the markup, and in between if we select any markup, the drawing tool takes up that shape and color for the next markup to be drawn ignoring the markup type and color we selected earlier. Is this the normal behavior. Why does the drawing tool take up the configuration of the last selected markup and overrides the type we define through - new Autodesk.Viewing.Extensions.Markups.Core.EditModeCloud(markupExt);
Thanks!
That's an interesting question. I believe the current behavior of markups is as-designed because one would typically only select a markup if they wanted to move it around, scale it, etc. That's why in the current implementation, selecting a markup automatically enters its edit mode.
At the same time I understand your view where if I already activate a specific edit mode, it seems strange that that edit mode would change after simply selecting another markup.
Let me bring this up with the engineering team, and in the meantime, I'd suggest using the Autodesk.Viewing.Extensions.Markups.Core.EVENT_EDITMODE_CHANGED event to detect a change to the edit mode, and if needed, reset the mode to the one you want.

MFC colored button with native win7 appearance

I am using MFC to create a dialog project and trying to impart color to the buttons.
I came to know that the only way you can do is to make the button owner draw. OnCtlColor() does not work for buttons.
I am able to color the button overriding OnDrawItem , but the problem is that , in the process the 3D cool look (with slightly rounded corner that you get in Win7) is lost.
Is there any way to retain the native look and color the button on top of that?
This is not a trivial task. As long as you are using themed controls (what you want), you cannot do more than the theme allows.
You would have to re-implement drawing of the button on your own, making use of the theme API as much as possible to retain themed look, yet sneak-in your color.
Though note that you can hardly achieve anything better than, what .NET WinForms do, when you set the Button.BackColor:
See also question how to set Button BackColor?
Disassembling the WinForms ButtonStandardAdapter.PaintWorker will give you some idea and API you need to use. Beware, you need to do lots of coding!
For C++/MFC code check out Vista themed Owner-Drawn and Full-Custom Push/Menu/Image Buttons on CodeProject. Which probably actually does, what you want already (the SetBackgroundColor method), so you might reuse it.

How to add a NSColorPicker to the application's main window?

I'm building an application to generate an array of colors based on a color chosen by the user.
The default on Mac OS X for color selection is to open a NSColorPanel containing multiple NSColorPickers. But, as the color selection process is the main interaction the user will have with the app, it'd be better to avoid the extra clicks and panel-popping in favor of a more straightforward way.
So, is there any way to add a NSColorPicker object to a window?
I know this is an older question, but check out NSColorWell. From the docs:
NSColorWell is an NSControl for selecting and displaying a single color value.
Interresting Question.
I strongly doubt it (but would love to be proven wrong). NSColorPickers are not NSControls (nor NSCells) so there's no clean wrapper to insert into a window.
Even if you were to instanciate an NSColorPanel and get a reference to its contentView and copy it (with all that defines the color picking controls) to your own window... there's no obvious way of obtaining the color value. NSColorPickers are plug-ins so you can't forsee the controls of a colorPicker.
The only other way I can see (and that's a stretch) would be to manually load the NSColorPickers plug-ins directly. I don't know how successfull this would be.
File a bug report and request the feature?

GTK - Don't highlight buttons on select / hover

I'm trying to write a kiosk GUI in ruby/gtk on ubuntu. I'm pretty fluent in ruby, but new to writing GUIs and not great with linux.
I'm using a touch screen, and am using our own images for buttons, e.g.
button_image = Gtk::Image.new(Gdk::Pixbuff.new "images/button_image.png")
#button = Gtk::Button.new
#button.add(button_image)
#button.set_relief(Gtk::RELIEF_NONE)
My issue is that when the buttons are pressed or remain selected (or hovered over, although this is less relevant with a touch screen), gtk shows fat, square borders around them. Obviously it's applying gtk's prelight / selected / active lighting to the buttons. I've tried changing the button properties in various ways, and also tryied hacking apart my theme, and while I can modify how the highlighting looks, I can't seem to completely get rid of it. Changing the color of the highlight via my theme is easy, but if I remove my setting there's still a default I can't get rid of.
Does anyone know if there's a way to stop it, or possibly make it transparent? Thanks in advance!
Sounds like you want to use exactly your image for the whole button, instead of putting an image inside the normal GtkButton - but still use all the normal behavior of the button.
The easiest way to do this is to just override the drawing. If you are on gtk2, connect to the "expose-event" signal, do your drawing there, and return true so that the default handler doesn't get run. If you are on gtk3, connect to the "draw" signal and do the same.
I tried meddling with the drawing as Federico suggested, but found that the most direct way to address this was instead to use an event box rather than a button. Event boxes accept clicks just like buttons, but don't respond to selecting, hovering, etc. In ruby, the code looks like this:
image = Gtk::Image.new("myfile.png")
event_box = Gtk::EventBox.new.add(image)
event_box.visible_window = false
event_box.signal_connect("button_press_event") do
puts "Clicked."
end
Most of this is exactly like a button; the *visible_window* method, obviously, keeps the event box from being visible under the button image.

Change Background of WP7 Application if Theme is altered

I need to change the Background Image of my Application if user changes theme from "Light" to "Dark" or vice-vesa in code behind. I hope these should be done in Page Loded event
#TimDams pointed you to one of the nice ways to detect what-theme-is-now-set, but I didn't notice there any information how to detect a change to the theme during the application runtime. The user could start your app, then bump forward to the menu, change the theme, and get back to your app. While you may think that your app will be tombstoned and then restarted and renavigated to your page with full cycle with all pageloads -- it is not 100% true.
Firstly, the PageLoaded is NOT a good place to do the initial check-and-set-styles, because, if you get that event called, then the page, probably, has already rendered once. If I remember well, the PageLoaded is invoked just after the first render. If this is true, then you will have to detect the colors earlier, for example in the LayoutUpdated (warning: this event is a great spammer. I mean, it gets called gazillions times. Attach a single-shot handler, you know, such that will instantly unattach-self on first invocation). Maybe you will be able to do it in the Page's .ctor, just after InitializeComponent. Or in the OnApplyTemplate or MeasureOverride, or at least ArrangeOverride -- the visuals should be mostly/fully available there.
Buuuut. I've intentionally 'bolded-out' the word "initial". With Mango, there's some multitasking getting more and more common, but even the pre-Mango 7.0 version does not guarantee that your app will be tombstoned. From my observations in early 7.0, for example, starting the MediaPlayer from WebBrowser component does not tombstone your app:) If you have some time to read, check WP7 recover from Tombstone and return to page for details on the "pause" vs "tombstone".
Anyways, if your app gets "paused" and the user switches themes in the meantime, I think (I've NOT checked) that your page will (in most of the cases) be just temporarily hidden and upon returning to the screen, it will probably not be re-created and will not be re-(Page)Loaded. If it is true, then you will have not so easy problem to solve, because your app may be paused, the OS rethemed, and your app unpased virtually in any moment of time and the only events you will get in the mean time are .... global events of App.Deactivated and App.Activated. It is possible that completely none of per-page events will fire [but I've not checked - before you do anything I suggest below, CHECK IT].
If this pessimistic view is really true, than in those events, you will have to detect the current theme (->Tim's post), then somehow inform your current Page that themes changed - or not. If you have your ViewModel at least a bit separated from the rest of the app (as it should be:) ) you have an easy option to do it: create in that ViewModel a set of properties (dp or inotif) like Brush Background, Brush Foreground, Brush Hightlight, and other that you need, and instead of harcoding colours in your XAML - bind to those properties. You may event want to create a separate class for all those many Brushes and other Styles, let's say "pub class MyCurrentAppTheme" and keep that props there, and expose such object from ViewModel - whatever. Just Bind your colors to whatever -- but whatever that will be "logically global" and that will be easily accessible from the App.Acticated event handler. Having that done, in the App.Activated, detect the current theme and if changed, so through all the colors kept in VM and set them appropriatelly. Voil'a, whole your App gets recoloured properly.
But mind that still - there might be some transient blinks and flashes between the rendering of cached old theme, refreshing databound objects, and redrawing fresh theme. I hope not, but I sense it may occur, especially when returning from fast-switch tool (long back press): I think that the device captures the 'last screenshot' of your app in the backbuffer and uses that throughout all the time the app is 'minimalized' to do transitions animations, to show the fast-app-switch overview and so on.. again, I've not checked, but I doubt that during such animations the pagecontents are 'live', it could be very demaning on CPU/GPU resources. Any one knows anything on that? It could be a nice test to have some looping animation on the page and then to switch out and check in the fast-switch overview, whether the animation moves or is halted!:)
If your application is tombstoned, all your controls will be recreated and the new theme will be applied. If you'd like to manage your light/dark specific styles in a similar vein to normal themes, you might want to take a look at a custom ResourceDictionary I blogged about a while back.
Unfortunately, as of Mango there, is a bug (?) related to fast application switching that causes the theme to remain unchanged in your application. The bug is outlined in this question and its linked posts:
Is there a bug when changing themes when app is deactivated and reactivated in Windows Phone Mango
My ResourceDictionary is still useful for the initial startup but it appears, unfortunately, that nothing can be done to workaround the Mango bug.
For this no event exists. You need to figure this out manually by comparing the PhoneBackgroundBrush color to see if the user has the dark or light theme and compare it with your last stored value.
Were you able to do some test on the App.Activate - Deactivate?
I decided to use a different path to solve the issue of dynamic theme change.
I've assigned to all text and buttons only system resource colors.
For the icons inside the buttons in the window instead of using PNG images-icons I used the in XAML and assing it a Foreground color from system resource.
For the buttons in the SystemMenuBar there is no issue as they are always on a dark gray background so the black PNG images work just fine.
Hoping this helps.
You can check if the dark theme is in use with this simple check:
public static bool CurrentThemeIsDark
{
get
{
return (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible;
}
}

Resources