Styling Buttons in WPF

February 13th, 2012

Having trouble getting rid of the built-in borders when styling a button in Blend?  Replace the ButtonChrome elements with Border elements.  Borders have most of the properties of ButtonChromes, so the switch is about as hassle-free as it’s going to get.

Basically, ButtonChromes are a tool that allows .NET to set the visual appearance of certain elements based on the theme set on the end-user’s machine (which is why you can’t edit the elements directly).

Here’s a quick overview:

  • Right-click on the element you want to style, select Edit Template > Edit a Copy…
  • Go into the XAML and find the ButtonChrome elements.  Change them to Borders.
  • Depending on the element, you’ll have to remove a few parameters; just look for the squiggly red underlines that tell you something’s wrong.
  • Once your ButtonChromes are gone and you can build without errors, you may want to go through the style you created and look for things that are referencing dynamic/system resources, and redirect them to local or template-bound values.

Be ready to push through a headache.  Blend writes some pretty ugly XAML, and I for one find myself working less in the Design mode every day.

Using DotLESS with ASP.Net/MVC3

February 3rd, 2012

I’ve fought with this for a couple of days, mostly because I’m not a programmer — I’m a markup jockey.  I’ve been using LessCSS for a few months, ever since I heard about it at HTML5.tx.  If you’re unfamiliar with it, it’s a tool that adds things like variables and mixins to CSS.  It makes theme development and modification a lot easier, and I really love it.

The Problem

The easy way to get started using LessCSS is to use the JavaScript implementation.  This turns a lot of people (me) off, because the thought of forcing a mission-critical resource like CSS to rely on Javascript — which may or may not be available — is horrific.

The second implementation that they offer is based on Node.js, which I’d sincerely love to get into someday; but it’s largely C-based, which is beyond my standard skillset.  I don’t want to have to implement a web server every time I want to sling a little style around!

The .Net Curveball

At FrogSlayer, we’re a .Net development shop.  If I want the wizards with whom I work to be able to add some horsepower to the back-end of the pretty sites I make, it means I need to work with ASP.Net.  Enter DotLESS.

DotLESS is a .Net implementation of LessCSS.  There’s some very simple instructions available on their website that will have a programmer churning out .less stylesheets in no time flat.

FLAW: Programmers don’t (usually) write stylesheets.  Designers do, and we’re the ones who are desperately trying to get this technology working!  The assumptions made in all of the documentation I’ve seen — essentially everything about .Net that programmers know and designers don’t — stopped me dead in my tracks.

The Solution

I beat my head against this for a couple of days, drank several whiskeys and even cried a little bit — but I finally put together a quickie set of instructions for getting DotLESS working with a new ASP.Net w/ MVC3 web application.  Here are my steps, recorded primarily so I can remember them.  This assumes you have Visual Studio 2010 and MVC3 installed.

  1. Acquire DotLESS
    • Go to https://github.com/dotless/dotless/downloads
    • If you don’t want to use Git to download the source and build it yourself, just download the ZIP file containing the latest release.
    • The only thing you really need is the dotless.Core.dll file in the ZIP file; extract it to your desktop.
  2. Open Visual Studio and create a new ASP.Net/MVC3 Web Application (I used the Internet Application template).
    • Add the dotless.Core.dll file to the project (wherever you like; I usually add a root-level Resources directory for things like this).
    • Make a reference in the project to the dotless.Core.dll file.
  3. In the Content directory, rename Site.css to Site.less
  4. In Views\Shared\_Layout.cshtml, change the stylesheet <link> tag from .css to .less
  5. Right-click Content directory
    • Add > New Item… > Web Configuration File 
    • Replace the pre-generated contents with the following:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
</configSections>
<system.web>
<httpHandlers>
<add verb="*" path="*.less" validate="false" type="dotless.Core.LessCssHttpHandler" />
</httpHandlers>
</system.web>
</configuration>

That’s it!  Build and run the project, and you should be able to start rolling LessCSS into the Site.less file (or replace it altogether).  Happy styling!

I’ve Won NaNoWriMo!

December 1st, 2011

Fourth time’s a charm! I started Nano’ing in 2008, and finally just won for the first time tonight. The novel itself is now about halfway finished — well, the first draft of it, anyway. Once I’ve had a little bit of rest, several glasses of Scotch and a good deal of Skyrim time to recover, I’ll get back to it.

Only 11 months until NaNoWriMo 2012!  Think you can write 50,000 word in a month?  Give it a try!

WordPress, SVN, and Local URLs

August 2nd, 2011

At FrogSlayer, we use VisualSVN for most of our revision control needs.  It’s recently occurred to me that I could be using SVN to sync the WordPress themes I’ve been developing, which would make it a lot easier to grab my laptop and head to another workspace if I start craving a change of scenery in the middle of a work session.

If that weren’t enough benefit, I recently lost half a day to a web server crash because GoDaddy deleted my company website’s stylesheet.  I had an old version, so I didn’t have to rewrite it from scratch… but it still took a lot of work to recover.  SVN is one of the best backups you can have.

Luckily for me, someone else at the office was responsible for setting up our VSN server — which unfortunately means I have no idea how to provide instructions for doing so.  Best of luck :)

Once you have SVN working, create a new repository and add a themes folder to it.  Then go into your wp-content folder in your development directory, save the themes in your themes folder to your desktop, and delete the existing themes folder.

Do an SVN checkout of the themes folder from your repository in the wp-content folder (where your old themes folder was).  Move the themes from your desktop into the folder, add them through SVN, and commit.

Now do this on your other computers, and syncing themes from one computer to another becomes a lot easier.

Virtual Host URLs

This article also made my life a lot easier this week.  By setting up virtual host URLs on my computers, I get to bypass some of the problems associated with absolutely referenced URLs in subdirectory deployments — and I get to use more entertaining URLs for local development.

With virtual URLs, you don’t have to use real top-level domains.  I’m now developing on my laptop at http://wordpress.lol.  Yes, it’s a little bit dumb, but I’m entertained.

Work vs. Business

May 11th, 2011

My life became a lot less frustrating when I figured out that work and business are not the same thing.  In fact, they’re diametrically opposed to one another in that you can’t do both at the same time, but they’re both essential to the success of your enterprise. (more…)

WordPress: Permalinks and references

April 26th, 2011

While attempting to deploy a new site using WordPress 3.1.2, I had a problem with the images being called in my header div not propagating anywhere except the “Home” page.  This can normally be fixed by absolutely referencing the images — simply place a forward slash in front of the image URL, like so:

<img src="/wp-content/themes/YourTheme/images.ImageName.png" />

(Note the “/” before wp-content.)

For some reason, this wasn’t working.  If I used anything other than the Default permalink setting, it would incorrectly reference the images, and they would not display.  With a little bit of fooling around, I was able to get it corrected.  While the steps are fresh in my mind, I wanted to make a record of how one can get a new installation of WordPress to work with pretty URLs:

These instructions assume that you’ve done your theme development in one environment (namely localhost on your computer), then migrated to a fresh WP installation on your server.  If you’ve done things differently, you’ll need to adjust accordingly.

1. Absolutely reference your images. As noted above, use a leading forward slash in all of your link URLs during development.

2. Install WordPress on the server. This is the server where it will run in production, i.e. http://YourWebSite.com.

3. Delete the sample page and “Hello World!” post. Delete them, then delete them permanently in the trash.  This is a necessary step.

4. Go to Settings\Permalinks and set your permalink structure.

5. Add pages and posts.

That’s it!  Keep in mind that these steps have worked exactly once for me, and I may have missed something.  Good luck.

The R-Word

April 22nd, 2011

If people were asked to think twice about using the word “retard(ed)” in reference to something ridiculous or stupid, they might stop. (more…)

Researching Food

March 28th, 2011

I’m adding a new habit to improve my lifestyle every month this year.

So far, I’ve resolved to drink enough water and re-learn Spanish.  I’m pretty consistent on the water thing, y puedo hablar Español mejor que el mes pasado.

I’m highly tempted to use my monthly resolutions to do something work-related, but I’m trying to keep them in the spirit of health and well-being.  This month, I’m going to start paying more attention to the food that I buy, more in an ethical sense than a dietary microscope sense.

(more…)

American George

March 24th, 2011

I’ve added a new site to my portfolio.  It’s a group blog for my family named American George, which got its name from my brother Jake.  That’s an interesting story, which I’m sure will see a great deal of detail on AG.

Everybody in my family likes each other, but we never seem to have a chance to talk.  I’m hoping this will fill the gap between the holidays.

 

Content Your Blog Can Live Without

March 23rd, 2011

When first launching a new blog, it’s natural to feel like you don’t have enough content.  You may feel like you have nothing to offer, or that no one will take your blog seriously if you only have one or two articles.

The good news?  You can control when people find out about your blog.  You’ll have a respectable cache after blogging for a month or two, so wait awhile before you start publicizing yourself.  In the meantime, there are a couple of things that everyone should always avoid putting on their blog. (more…)