Tag Archives: C#

Setting a Windows Phone Button Background in C#

There might be a case where you need to set the background color of a button in code rather than in XAML. Or you might define a style in XAML with a particular button background color, but would like to change the background color in an event handler. For example, let’s say you created the following button in XAML:

<Button Content=”My Button”
Background=”{StaticResource PhoneAccentBrush}”
Click=”RegisterSelection_Click”/>

Now let’s say that when the user clicks the button you want to change the button’s background color to give another way of indicating the button has been selected. You can do the following in C#:

private void RegisterSelection_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
btn.Background = App.Current.Resources[“PhoneChromeBrush”] as SolidColorBrush;
}

I am using this in an app I am currently working on and it works well. Give it a try.

Windows Phone 7 for Absolute Beginners

Windows Phone 7 for Absolute Beginners is a fantastic video series from Bob Tabor, posted on Channel 9. Below is the course description:

“This video series will help aspiring Windows Phone 7 developers get started. We’ll start off with the basics and work our way up, so in a few hours you will know enough to build simple WP7 applications, such as a GPS aware note taking application. We’ll walk you through getting the tools, knowing what an if statement is, to using the GPS built into the phone and much more!”

The videos are just my speed, slow, well thought out, and Bob does a great job of explaining WHY to do something rather than just dropping in 200 lines of code from a snippet and telling you, “it’s just basic stuff, we won’t cover this”.

If you are new to programming, particularly C#, XAML, and Windows Phone, I think you’ll find this series of videos very helpful. He starts you off with the very basics and works up to developing a note application.

Connectivity Manager for Windows Phone 7/8 App Released

A few days ago I released my first Windows Phone app, Connectivity Manager. You can find it here in the Windows Phone Store. It is a simple application that provides links to the settings pages for Wi-Fi, Bluetooth, Cellular/Data, and Airplane Mode. There are plenty of other apps out there that do the same thing, some simple, some fancy, but this is my first app and I needed to get my feet wet.

The app uses toggle switches to indicate the status of the various settings. Unfortunately, it isn’t currently possible to determine the status of Bluetooth and Airplane Mode through the Windows Phone Application Programming Interface (API). So for now the status for these two settings are permanently set to off. Here is a screenshot, the one you’ll see in the Windows Phone Store.

I wanted to use the toggle switches because they mimic the controls used in the operating system for those settings. Ideally, you’d be able to change the settings directly through my controls, but there are appropriate reasons this can’t be done, particular with regards to security. You wouldn’t want an app unknowingly toggling on and off your Wi-Fi connection, for example, transmitting data without your knowledge and such.

If the WP API is updated in the future to allow determining the status of more connections settings, like Bluetooth, Airplane Mode, and Internet Sharing, I will push out an update.

Download Connectivity Manager from the Windows Phone Store. It is free and there is no advertising. Clean and simple.

If you have any suggestions for this app, send me some feedback.