Monday, 2 August 2010

Adding triggers to WPF User Control

I've hit this issue a few times, always forgetting the solution afterwards. It also is a problem that doesn't feel like it should be there. It regards using User Controls in WPF, those with attached XAML files, and wanting to add some triggers that affect some of the elements declared in the XAML.

The problem is that if you want to add a trigger in the UserControl.Triggers collection you get a run-time error telling you only EventTriggers are available in that section. If you try an ugly use of the style triggers collection liks this: UserControl.Style -> Style -> Style.Triggers, you get a compilation error saying you can't use TargetName in a Style setter.

There are two solutions, one uglier than the other. One is to use a multi binding to add all the things that affect a property in a setter. Of course, you need a converter class for each one. Yuck! The other solution is to add a setter in the style of the element you want to change, therefore eliminating the need for the TargetName attribute. This is what I use when a trigger is badly needed. I know, fugly.

Update: I have tried to create an attached property that would act like a control trigger collection that would accept any type of trigger. While that was not a problem, I got stuck at the point where every property and value had to be fully qualified, making the style with trigger option look more attractive than this. It appears that the XAML reader itself handles triggers differently and the way it qualifies property names is hardcoded somehow. If anyone gets a handle on how to solve this get a free beer from me :)

Saturday, 31 July 2010

Tenpō Ibun Ayakashi Ayashi aka Ghost Slayers Ayashi

the Ayashi I quite liked this anime series, one which combined with success the typical demon slaying organisation with a background of describing the culture and history of Japan. In that regard it is quite similar to Ruruoni Kenshin, but without the romantic side and a bit more supernatural.

The plot is set somewhere in the middle of the 19th century, when a government official decided to create an organization to defeat Youi, or demons. These people are called the Ayashi. The main character is a guy that has the power to extract weapons and other useful tools from the names of things. It is a beautiful concept, since in Japanese the characters are very complex, have a lot of meanings and have a habit of evolving through history. Usually a demon can be defeated with a weapon made from it's name, which usually holds extra significance as to what the demon's reason to be is.

The series also describes a very feudal and disgusting Japan, where people are constrained to ridiculous levels by etiquette, social ladder, politics or gender. Many a time, to ensure the survival of their little group, their leader resorts to despicable acts which the team performs with disgust, but a complete lack of choice. Women are treated as commodities, low rank people as livestock, while the rich and powerful engage in complex political struggles to ensure their survival. Scholars are being imprisoned for studying Western concepts, foreigners are considered a bane that people should not come across, while people without a family name and land are tatooed as "floaters" and arrested if caught inside cities.

A lot of the details of the show are about Japanese customs, history and view of the world, so I naturally enjoy this as a background for a fun fighting story. Other people obviously did not think the same way, so it only has 25 episodes, even if originally 52 episodes were planned.

I haven't finished the series yet, I still have the last five episodes to see, but so far I have enjoyed it. There is a manga for it, too, but I didn't find it free online.

Thursday, 29 July 2010

Turn on/off ReSharper code analysis

Update February 2016:If you just want to disable R#, like it is not installed, go to Tools → Options → ReSharper → Suspend/Resume

I've been using ReSharper (R#) for a long time now and I can tell you that if you are a Visual Studio C# developer and you are not using it, you are missing out. These guys must have the greatest job in the world: develop for developers. Or could it be the worst job, since doctors always make the worst patients? anyway...

I have been preaching about ReSharper for about 4 years now and the most common complaint from people new to it is that it makes things go slowly in certain situations. The thing is, R# is doing so much stuff in the background, that I find it amazing it moves so fast as it does. It is a valid complaint to want to have the same speed of typing and moving around that you have in the normal Visual Studio environment and still have the many features provided by ReSharper.

So, my solution was to have a command to "pause" the ReSharper analysis until I need it. The scenario would be:
  • Suspend analysis and regain swiftness of typing
  • Write your fingers off, since you already know what to type and even Intellisense feels like slowing you down
  • Resume the analysis and get all the R# goodness
In other words, something like writing your code in notepad and then copy pasting it all in the VS window.

Well, as most of the time, the R# have thought about it already! You have two possible options. One is using the commands ReSharper_Suspend, ReSharper_Resume and ReSharper_ToggleSuspended. You can either bind them in the Tools -> Options -> Environment -> Keyboard to whatever combination you desire, or go to Tools -> Options -> ReSharper -> General and use the Suspend button. This is equivalent to enabling/disabling the ReSharper addon. Since it is a very large addon and needs a lot of resources and hooks, this option is terribly slow. It does have the advantage of freeing all memory used by R#. The second option is more what I was having in mind: the command ReSharper_EnableDaemon. It sounds kind of like "Release the Kraken!" and it works in a similar way. What it does is suspend/enable code analysis on the current file! It is already bound as a global shortcut on Ctrl-Alt-Shift-8. It works almost instantly and enables the scenario I wanted.

Bottom line: Ctrl-Alt-Shift-8 to suspend/resume code analysis on the current file so you can type like your livelyhood depends on it. Again, thank you, JetBrains!

Update: It seems on older versions of ReSharper (not 5), the shortcut is Ctrl-8.

Tuesday, 27 July 2010

YUM errors on Fedora

Another Linux related post, this time about errors when trying to use yum to update or install some packets on Fedora 9. The error I encountered is [Errno -3] Error performing checksum when trying to get primary.sqlite.bz2, eventually ending with an ugly Python error AttributeError: 'NoneType' object has no attribute 'cursor' .

In the etc/yum.repo.d folder there are some files with the .repo extension. Each one contains some modules that can be enabled=0/1. Those modules are used by yum to download and update files. Yes, you will see yum failing and "trying another mirror", which means another server, but not another module! Therein lies the problem. I had a repo enabled that was not for Fedora 9, but for Fedora 14 aka Rawhide. The checksum was obviously failing.

The solution is to enable only the fedora repos, and disable everything else. Eventually, start enabling and disabling different modules and see what works and what doesn't.

My problems were not over. After running yum update I was getting Missing Dependency errors. Analyse each one and see what you can do. In my case, the subversion packet wanted a libneon.so.25 file. The problem was not in the neon file, but in the fact that the subversion packet that threw the error looked something like subversion-1.6.6-0.1.el5.rf.x86. Notice the el5 portion which identifies the packet for CentOS, not Fedora 9. It's the wrong packet.

Use rpm -qa | grep el5 to get all the packets that are wrongfully installed for el5, then use yum erase <packet name> to remove it. Now the update and yum should work fine.

Sometimes the errors lie in corrupted caches. You have two additional commands that might help, although in my case I don't know if they had any effect:
yum clean dbcache
rpm -rebuilddb

Hopefully this will clear things up for other Fedora noobs :)

Saturday, 24 July 2010

Stellvia of the Universe (Uchū no Suteruvia)

The main charactersStellvia is an anime with teenage kids saving the world. It starts like a kind of Harry Potter, only the main character is a girl, the academy is in space and there are no Voldermort or Slitherins in sight. All in all it was a fun series to watch, but so easy going and adolescent oriented that I am sure it will not remain in my memory for long.

The plot is simple enough: Earth was devastated by a supernova blast wave, it recovered, then it set out on a mission to defend the Solar System from the second wave, slower but deadlier. Their solution was to create a bunch of stellar academies, fill them with children trained by dedicated teachers, while the whole world stands united against this coming disaster. One can see from this plot alone that the focus is not on realism nor human nature. However, since it does touch all the Japanese topics of choice like pursuit of perfection, positive competition, love between school children and loyalty and "gabatte"-ness, it was nice to watch and I have easily enjoyed it.

Composed of 26 episodes, the series does leave room for more, like humanity exploring the stars. The aliens were never explained and the last episode does show a rebuilt Stellvia star academy with the trainees that saved the world as full students welcoming a new batch of recruits. However, it seems like a second season of Stellvia will never happen, due to creative differences.

OneManga removes all Manga scanlations from site!

What a sad day this is. I have been reading manga at OneManga on an almost daily basis for a few years now. I liked how you can easily find the manga you want to read, then go through it without tons of ads and crap distracting you. Today, I entered their site and this message appeared:
"There is an end to everything, to good things as well."

It pains me to announce that this is the last week of manga reading on One Manga (!!). Manga publishers have recently changed their stance on manga scanlations and made it clear that they no longer approve of it. We have decided to abide by their wishes, and remove all manga content (regardless of licensing status) from the site. The removal of content will happen gradually (so you can at least finish some of the outstanding reading you have), but we expect all content to be gone by early next week (RIP OM July 2010).

So what next? We're not really sure at this point, but we have some ideas we would like to try out. Until then, the One Manga forums will remain active and we encourage all of you to continue using them. OMF has developed into a great community and it would be a shame to see that disappear.

You can also show us some love in this moment of sadness by 'liking' our brand new Facebook page. It would be nice to see just how many of you came to enjoy our 'better than peanut butter and jelly' invention.


Regardless of whether you stay with us or not, on behalf of the One Manga team, I would like to thank you all for your unwavering support over the years. Through the ups and downs you have stuck with us, and that is what kept us going.

As a certain Porky was fond of saying... That's all folks!

Time for me to go lay down and let this all sink in.

- Zabi


Sure, there are a lot of free manga sites out there, but none of them had the soul of OneManga, a place where obvious passion was fueling things and not financial greed. I will soon add a post with the newest place for free manga. I will also have to update all manga links in the blog. Ugh! Nothing good seems to last forever...

Tuesday, 20 July 2010

Return of the Crimson Guard by Ian Cameron Esslemont

Book coverIf there was any doubt about the style of writing and book structure for the first novel from Ian Cameron Esslemont in the Malazan universe, the second book: The Return of the Crimson Guard, dispelled any. One can barely see a little more focus on action than on description compared to Steven Erikson, but, having read it, I feel like this is the tenth novel in the series, not the second in a parallel Malazan world.

First of all, it is a full length book, similar in size with the ones written by Erkison. Again we see an amassing of forces, set to converge towards the climactic end. There are the Avowed of the Crimson Guard with a full army of mercenaries in tow, there is Lasseen, empress of the Malazans, there are Seguleh, man-beasts, D'ivers, Soletaken, mages of huge power, Claws, Talons, Seti, Wickans and the all pervading regular Malazan soldier, with focus on our favourite sort: the sapper :)

I have to say that the writing is so similar to Erikson's, that it even acquired the same problems. There is a lack of finality to just about anything. One just knows that a lot of questions will remain ... not unanswered, but simply ignored... and that the next books will bring more wonder, more magic, more characters, all dancing around this huge singleton of a main character which is the universe of the Malazan Empire. It's refreshing, it's great... it's annoying!! :)

Having said that, this was another great book, one of those writings that make me want to abandon programming to start writing, even if I know nothing about it, one of those books that make me want to abandon watching movies altogether, for lack of detail and significance. Now my big dillema is what should I read next...