Category Archives: Programming

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.

A Beginner’s Adventures in Programming (ABAP)

If you don’t already know, I’m very, very new to programming and application development; and as of this writing I’m 41 years old. Compared to many programmers I’m probably 30+ years behind the curve. But who cares?

I didn’t always feel that way. For years, I’ve dabbled in programming, ranging from Excel macros to web development to most recently taking introductory college courses in Assembly, C, C++, and Java. But I’ve always walked away because it just seemed too daunting. There are so many languages out there and the technology moves so quickly that it just didn’t seem to make sense to start so late in life to learn something new, something that I never felt I could get good at quickly enough to keep up. Well, that was the old me.

Something happened a month or two ago, a switch flipped in my head. Perhaps my brain finally figured out how to catch the exception and handle it properly. Honestly, I don’t know what happened, and I really don’t care, because I finally found direction. Now I’m learning C#, XAML, JavaScript, and HTML/CSS. I published my first Windows Phone app a few weeks ago. As of today, it’s been downloaded 921 times. That’s 921 random people that felt compelled enough to at least check out something I created. Whether or not they continue to use it is another matter, but at this point I don’t care. To me, it’s all about the experience.

Having listened to various podcasts for the last few months, I hear lots of comments from the podcasters that many people have dipped their toes in programming, but for various reasons gave up — life got in the way, it seemed too hard, they didn’t know where to go with it, etc. If you’re one of those people (I was definitely one of those people), I’d like to share my journey with you so that you can see that no matter what your age, what your current occupation (I’ve been in finance my entire professional career), you can learn to program, you can do something useful with it, you can stretch your mental abilities and be on a never ending path of learning, and, most importantly, you can have fun doing it.

Let’s get started…