Giving a custom color to a Toggle Switch when it is on mode in xaml? - xaml

I want to give a different color to my Toggle Switch when it is On mode.I was going through the Standard Style but couldn't find anything which i am looking for.

First, I'd check the default template again. You can bingoogle it to get this:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709931.aspx
You might then want to change the "On" visual state Storyboard to update the Background of the "InnerBorder" element or add another background element and use a DoubleAnimation in the Storyboard to control its Opacity.
The easiest way to modify the template might be to use Blend. Similar to what I have done in my answer to this question:
Listview selection display with no padding and no checkmark

Related

Programmatically make color filled UIBarButtonItem

I have a UIBarButtonItem with the UIBarButtonSystemItemSearch type. I can programmatically change the tint color, like so:
searchButton.tintColor = [UIColor purpleColor];
However, what I'm trying to do is figure out a way to programmatically "fill" the button (i.e. the magnifying glass) with a given color. More generally, I'm trying to use a change in the icon to indicate that the search functionality is active.
I really like the built in search icon, but the lack of an obvious fill functionality is annoying. Is there any way to do something like this without creating an entirely custom button/icon? If not, what's the easiest way to utilize the existing search icon to create a custom button that does have the ability to be filled?
First off I would suggest simply using the tintColor to show your selected/unselected states without trying to mess with the shape itself since it is much easier and will convey what you're trying to do. Keep in mind that in this specific case, the magnifying glass may not even look right if it is filled in, that shape is very specific and people are used to seeing empty space in the circle.
If you want to continue on that route though, no you cannot easily change the built-in search icon. Your options are 1. programmatically take a snapshot of such an icon on the screen and try to manipulate that using CoreGraphics (not a great solution) or the better solution 2. which is just to get/make your own image and then you don't have to do any of it programmatically.

Custom button in Windows 8.1 app

I have a requirement to create a button in a Windows 8.1 app which has an icon and a text label. The icon will be a symbol from Segoe UI Symbols and the text label will be Segoe UI Semibold at a smaller text size.
I want to be able to reuse the button in different places within the app, using different icons and text labels.
How show I go about this? I could create a button and then edit the ContentPresenter to have a horizontally oriented stack panel with two TextBlocks, but then how could I reuse this? And how could I change the text in the two different text blocks?
Should I create a separate custom control with separate dependency properties for each of the textblock strings? I'm interested in hearing what you would do.
thanks
Create a simple Style. To make it easy, I would base it off the standardized AppBarButton style. You can format it to whatever size you want (I have done something similar to make a larger button or one with text on the side).
Have the main icon simply be a ContentPresenter which binds to the Content using a TemplateBinding. Make sure to set the FontFamily to Segoe UI Symbol. Have the text label pull from AutomationProperties.Name, similar to how the AppBarButton style does.
Then, whenever you want to use this just do:
<Button Style="{StaticResource MyCustomButtonStyle}"
Content="" // Where "000" is replaced by the number of the icon you wish to use.
AutomationProperties.Name="Text Label"/>
This should be extensible and easily reproducible to whatever location you need. When copying over the AppBarButton style, I suggest removing the artificial size limits (specifically the width of the main content Grid). I do suggest either giving the Text Label a fixed size or having it pull its size from the specified parent Width, so that it will Wrap correctly.
Hope this helps and happy coding!
Are you desiring to create something like for an AppBar? Take a look at AppBarButton and the style/types it supports. In Windows 8.1 we added some things around SymbolIcon specifically. Since you basically want two pieces of 'content' for your style you'll have to re-purpose one property (unless you create a custom control which doesn't sound needed for this scenario). Using AutiomationProperties.Name for the visible label is a good idea because it will also help with accessibility by default for those users.
Investigate the style for AppBarButton to get you started.

Add / Remove buttons in NSOutlineView

I have a Source-View (NSOutlineView) with two Buttons at the bottom. I added an NSBox so that the items don't "shine through" when they're behind the buttons.
This works fine when the window is active:
But as soon as I deactivate the window the NSBox still has that active color, rather than a dimmed version to match the NSOutlineView's background color:
How can I make sure that those two colors always match. Also using a specific color is a bit of a hack since the color NSOutline uses might change at some point.
Update: Apple's Mail.app as well as Things seem to have a solution for that problem. :-/
#Neha put me on the right way to find a solution.
I write it in Ruby because I work with Rubymotion but it's easy to translate :)
Assuming you have a box outlet for the NSBox, you can set it to transparent when the window loses the focus and do the opposite when it becomes the key window, using the appropriate delegate methods:
def windowDidBecomeKey(notification)
box.setTransparent(false)
end
def windowDidResignKey(notification)
box.setTransparent(true)
end
And the result looks fine with the focus:
And without it:
The solution is to keep a reference to the NSOutlineView's backgroundColor property as it is a special NSColor that dynamically changes depending on the key status of the parent window. Set the color of your custom view to that that reference. When the window loses/gains key status, call setNeedsDisplay: on your custom view to redraw it using the new color. Use KVO to observe NSWindowDidBecomeKeyNotification and NSWindowDidResignKeyNotification. Note that pointer to the color stays the same, but the actual color represented by the reference changes. The solution is explained here.
In the attributes inspector of NSBox,
set display to transparent

WP8 PhoneAccentBrush doesn't affect TextBox focus border

I'm trying to make my WP7 app work well on WP8 (by compiling it as a WP8 app).
In my app, I'm changing the PhoneAccentBrush's Color which seems to work fine still, however TextBox's in WP8 now seem to show a border around it when the textbox is in focus (this wasn't happening for me on WP7). This border seems to always use the System's accent color instead of using the changed color like every other control.
Any idea what's going on here and how to change it? The red accent (if that's what the user has chosen) really clashes with my app's colors!
I would call overriding the accent color a hack. I would avoid setting the accent color and create a template for your textBlock.
Blend makes this very easy by allowing you to copy the default template and make changes to it.
Right Click the textBox in the Objects and Timeline pane, then select Edit Template -> Edit Current. Then select the States tab and select the Focused FocusState, then edit the border brush. Save and reuse the template as needed.
I did notice the textBox control template has changed in 8 and now defines the focus state border brush, although it does default to the PhoneAccentBrush.

Change tint color of keyboard for UITextField

I would like to set a custom color for the keyboard that is associated with a UITextField. I see that I can set the UIKeyboardAppearanceType, but I would like to be able to set the color to arbitrary color, rather than just change to a different default setting. I was hoping it would be as simple as something like this:
keyboard.tintColor = [UIColor colorWithRed:...]
Any suggestions?
There's no public API to access the system keyboard, so you're out of luck without re-writing UIKeyboard from scratch (which is a bad idea), or finding some private API to do the job (which is a bad idea if you want to submit to the App Store).
You could use Alert style keyboard and place a view in the background with a background color of your choice. This will make the keyboard a different color.
In Xcode look for the 'Keyboard Look' attribute in the Text Input Traits section of the Attributes Inspector. Can toggle between Light/Dark.