XAML and Data Binding

Posted on Sunday 9 March 2008

Xaml is actually fairly easy to learn, I was trying to show someone how you accomplish a data binding between it and your code. Here are two examples of a bound text box:

<textbox width="100" maxlength="50" text="{Binding Path=BlockDesigner}">
</textbox>

That is a simple binding. You can see the text being bound to a data variable called BlockDesigner.

                        <textbox width="45" maxlength="50" isreadonly="{Binding Path=IsChecked, ElementName=blockMonAuto}">
                            <textbox.text>
                                <binding path="MonLimit" notifyonvalidationerror="True">
                                    <binding.validationrules>
                                        <exceptionvalidationrule>
                                        <rules:intrange min="0" max="2000">
                                    </rules:intrange>
                                </exceptionvalidationrule>
                            </binding.validationrules>
                        </binding>
</textbox.text></textbox>

This is a more complex binding, you can see the binding was created using a separate element. The reason for this is that it is using a validation rule to make sure that the text entered is an integer.

For all this, all you have to do in the code-behind is assign a data source.

BlockPanel.DataContext = MapStudio.Settings;

In this case, the above text box is contained within a UserControl that I named BlockPanel. Because WPF looks for a data context at the element first, then checks all the parents above, it eventually finds it and uses it appropriately. This also saves you from having to assign the data context to every single textbox or element you want to use.

There is some pain involved, though, you can only bind to properties, and you have to design them a specific way so that the window knows that they have been updated. Overall, though, the extra step in the design (which is not at all a pain if you have, say, a snippet to do most of the work) is little enough to pay for the convenience.

Vassi @ 2:06 pm
Filed under: Uncategorized
The Good Left Undone

Posted on Saturday 8 March 2008

Every once in a while, when I’m thirsty, I’ll look at a Sprite and see it sparkling and clear, the fizz murmuring to me from the glass. It looks refreshing, it promises me said refreshment, and it lies. Every time.

The bad thing about bad habits is that they are hard to break. Here’s to trying to break a few this year. I realize it’s a little late for the New Year resolution bandwagon, but in the end it doesn’t matter what time of year it is, so long as the commitment exists.

Vassi @ 6:08 pm
Filed under: Quirks
Why Reflection Rocks - A practical example.

Posted on Wednesday 5 September 2007

So, as previously stated, there is a MUD in the making. Now for those of you not in the know, one of the hottest things you want to get into your MUD is the ability to edit things on the fly. In the old, dark, days you would have to edit text files to accomplish this. Sometimes, you would even have to restart your server in order for these changes to take effect. Nowadays, there are a million and a half ways to avoid this.

In any event, this leaves developers the problem of how to edit things. Keeping in mind that this is a text based world it seems almost certain that you’ll be dealing with strings, and that means parsing. Don’t we all love parsing! I’ll leave that topic to another post, as I still plan to experiment with several different parsing techniques, but let’s suffice it to say that we want to take a string and break it down to key and value pairs. For instance “edit thing name=sword power=10 value=10″ This gets broken down into a dictionary where the keys are name, power, and value and the keys are sword, 10, and 10.

Well thats fine and dandy, except now I have to loop through this dictionary and check if the key is valid, and then apply any sort of formatting or constraints to the data. For instance, lets say value can’t go above 10. You end up with a tedious switch, or a long string of IF statements. Now say your object has over 70 possible settings, and that’s just one class. You have to make just about every system in your MUD editable, classes, guilds, spells, spell lists, players, items, monsters, monster lists, regions…I could go on. (Really, I could.) Writing all that validation code, when most of it will be copied and pasted anyway because theres only so many different ways to deal with ints, is stupid. I know it’s stupid because thats the way I did it, at first. Enter Reflection:

(more…)

Vassi @ 10:36 pm
Filed under: CSharp and Programming and MUD
Open Source…here I come?

Posted on Saturday 1 September 2007

I’ve decided I highly dislike Plesk. I like windows, and I like the .NET environment, but Windows web management is still such a black box compared to Unix tools. Plesk is about as unintuitive as it comes. Blarg!

That isn’t really the point of this post though. Mostly I’d like to talk into the void about some design decisions on the MUD I’m building. I’m still not sure I’m into the open source thing. Sure i’ve used some things i’ve found through open source but never anything major and usually I only borrow the concepts involved as opposed to lifting the code wholesale.

This changed a little, however, as I was ripping out chunks of my old codebase (its in a state of re-write at the moment) and compartmentalizing them. I realized that the bulk of my connection handler is code that I derived from an old C++ book called “MUD Game Programming” by Ron Penton. While, again, the code was in C++, and i’m not fluent in C++, I still lifted alot from the text. I made some distinct changes to the way things interact but still, if any part of my code bears sharing, that would be it.

The socket programming was, by far, the one thing I knew absolutely nothing about. Programming logic, structures, that I could handle - but grasping the whole socket thing was a bit over my head at the time. If it weren’t for that book, and some other resources, I wouldn’t have known where to start.

Theres a sample program included with the DLL, and source for both, here: Google Code

Theres a code sample after the break… but otherwise thats it.


V

(more…)

Vassi @ 10:27 pm
Filed under: CSharp and Programming and MUD
Getting through Work.

Posted on Thursday 28 June 2007

So i’m sitting here at work, as I often am during the week, and it strikes me that just about everyone is bored out of their mind while at work. The question, really, is how different people deal with it.

Personally I prefer to listen to audio. At first I used to listen to music on my iPod but after a while I knew all the songs by heart. Unfortunately i’m not rich so I don’t have the luxury of buying new CDs every other day. Worse, my iPod is the older (mini) style that only holds 4 gb so it is extremely annoying to figure out what I want to delete so I can put new stuff on it.

Anyway. Nowadays I listen to podcasts, and let me just say - if you listen to music at work, you definately want to delve into the podcast arena. The thing about listening to music was that after a while there was nothing new. Except for a few songs that I still like alot the rest were just filtered into white noise and so my day dragged on just as always. With podcasts, particularly those in radio talk show format, a part of your brain is listening to whats going on (hopefully the same part that usually counts down the seconds between each break).

Anyway, the main one I listen to right now is MyExtraLife, I started listening to the archive from the beginning so its lasted quite a bit (130 shows at one hour each). You can also check out the short, but funny as hell, ones from PennyArcade and if you like retro gaming you can search for Retronauts, though I beleive those may not be coming back in July. Either way, I recommend you look through the Podcast directory on iTunes, theres a podcast out there for whatever interests you.

Thats all for now, i’m tired of alt-tabbing every time the boss walks by.

 P.S. If you’re uncoordinated or work on a high-rise, podcasts may not be for you.

Vassi @ 12:55 pm
Filed under: Uncategorized
It is done.

Posted on Wednesday 23 May 2007

I’ve finally settled on a hosting home.

It will take me a little time to get settled in, but it will happen eventually. More later.

admin @ 12:48 am
Filed under: Uncategorized