The Stochastic Game

Ramblings of General Geekery

Posts with tag 'net'

    Making WPF controls double-clickable

    A common UI pattern features the ability to double-click on a control to go in “edit” mode. So for example, you have a TextBlock that shows you the name of an object, and you can double-click it to change it into a TextBox where you can edit that name. At this point, it’s easy to hook up the MouseDoubleClick event, or some other mouse event, but that’s not very MVVM-like, is it?
    Read more...

    Xaml serialization quirks and gotchas

    I recently had to build a little tool that would read its configuration from a XAML file (because XAML serialization is, most of the time, better and more customizable than standard XML serialization). The trick was that this tool had to be built on top of .NET 3.0 – not 3.5 or 4.0. And I discovered that there are a few little gotchas in .NET 3.0’s XAML serializer that I, somehow, never ran into before.
    Read more...

    Writing a custom Main() method for WPF applications

    Creating a new WPF project in Visual Studio gives you the following pretty simple application markup and code: <Application x:Class="WpfApplication2.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml"> </Application> namespace WpfApplication2 { public partial class App : Application { } } Understanding how it really works, and how to supply your own custom Main() method, is just a search query away. You basically need to change the application’s build action from “Application Definition” to “Page”, create a constructor that calls “InitializeComponent”, and write your Main() by eventually calling one of the application’s “Run” method overloads.
    Read more...

    Experimental IronCow branches

    I created 2 experimental branches for future versions of IronCow. “IronCow Mobile” is a branch that adds support for the .NET Compact Framework. Thanks to jwboer for the initial patch. “IronCow Local Search” is a branch that adds local search for tasks. We basically cache all the tasks in memory, and handle search queries locally, instead of sending a request to the RTM server and parsing the response markup. The lexical analysis and AST building of the search query is a bit dodgy, as I can’t get a proper tool like ANTLR to work with RTM’s search grammar (probably me doing something wrong), but it’s not too much of a problem right now since search queries tend to be quite short, and we already are significantly faster than a web request.
    Read more...

    Target the .NET Compact Framework using Visual Studio Express

    Microsoft only supports Visual Studio Professional for developing Windows Mobile applications and, more generally, code based on the .NET Compact Framework. You get nice things like application deployment and emulators and remote debugging and all. But if you just want to compile something against the .NET Compact Framework, for example to check that you’re using supported methods and classes, you can do that with Visual Studio Express. Create a project in Visual Studio Express and open it in a text editor.
    Read more...

    IronCow and the design for testability

    IronCow is a library that wraps the Remember The Milk (RTM) web services. The “upper layer” of the IronCow API is an object model that stays in sync with the server and is designed with data binding in mind. Of course, one of the things that went into IronCow’s design was testability. IronCow ships with a suite of unit tests that, well, test that the API is working fine. However, there’s another testability aspect: how the clients of your API are going to test their stuff.
    Read more...

    Fixing a bug can cause bugs

    Microsoft apparently fixed something in .NET Framework 3.5 Service Pack 1 that previously didn't work, or somehow worked differently. As a result, Milkify will crash if used on a machine that doesn't have this service pack installed. What you get is a XamlParseException that says that a ContentStringFormat property cannot be converted into a TemplateBindingExtension. This is because Milkify is using its own WPF skin where, among others, the check box control has a new custom template.
    Read more...

    WPF application patterns continued: convention over configuration

    In my previous post on WPF application patterns, I went over a few of the most common patterns available, and gave some pointers on how to implement them in WPF. I mentioned how you could use a dependency injection framework to decouple the implementation of your views and controllers from each other. However, the problem when using dependency injection out of the box is that you need an interface to bind to.
    Read more...

    Announcing IronCow

    One of the projects I'm working on at home, IronCow, is now in a state of "somewhat usable alpha". It's a .NET API that allows developers to use Remember The Milk, the to-do list website, from any .NET language. IronCow is composed of two layers. One layer is a "dumb" wrapper around the public REST API, in way very similar to what FlickrNet does with Flickr's own REST API. The second layer is a "rich" object model that exposes your tasks (and other data) through classes that stay in sync with the server as you manipulate them.
    Read more...

    WPF application patterns

    There's quite a few articles about using the MVC, MVP, MVVM and other MSomethingSomething patterns with WPF applications out there, but I think there's still quite a few things to say on the subject before we can implement all those wonderful acronyms from A to Z without too much worry. The goal of each of those patterns is to achieve separation of concerns for code reuse, scalability, extensibility, and testability, along with that warm fuzzy feeling you get when you look at your code and you think "wow, this is nice".
    Read more...

    Almost everything you need to know about XAML serialization (part 2)

    In part one of this little simple series, we saw how to use XAML as a file format for our own custom types. However, we wanted to reduce the verbosity of XML for specifying objects with only a few properties. This can be done with MarkupExtensions. We saw that the XAML serializer is asking if our types can be converted to the MarkupExtension class. Let's give our CustomizableEngine class the ability to do that:
    Read more...

    Custom provider attributes in a configuration element (part 2)

    In the first part of this little series, we implemented a simple, read-only way to get custom attributes from a configuration element, using a provider pattern use case. We ended trying to modify the configuration file, without much success. Right now, we have the following method, called at the end of the program: private static void SimulateConfigurationChange() { var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var section = configuration.GetSection("cookieFactory") as CookieFactoryConfigurationSection; section.CookieProvider.Options["maxCookies"] = "6"; configuration.
    Read more...

    Custom provider attributes in a configuration element (part 1)

    A common pattern in .NET is the "provider pattern", where you have an abstraction for pulling data out of something (a database, a file, your ass, etc.), and one or several implementations of this interface (usually, one for each "something" you can pull data out of). For this example, we're going to get cookies (the biscuit, not the browser token, you sad nerd) from some "cookie provider". public class Cookie { public string Flavor { get; set; } } public interface ICookieProvider { Cookie ProvideCookie(); } class Program { static void Main(string[] args) { ICookieProvider provider = GetCookieProvider(); Cookie cookie = provider.
    Read more...