Run.To.The.Hills

.Net

Dynamic parameters in XPath WPF bindings.

by rob on Mar.12, 2009, under .Net, Development

A graphical depiction of a very simple xml doc...

Image via Wikipedia

Since its been a fair while since I posted anything with technical content, I thought I’d lighten the atmosphere with some hardcore XAML extending ;)

I was asked this question a while back, how to parameterize an XPath query in a binding. Well, it is a bit of problem, you know, ranking right up there with global warming, world peace, North Korean space program crisis etc, and like most lazy developer’s (that’s a good thing btw!) I googled first to see what I could turn up.

There were plenty of scams for solving global warming, but not one for Dynamic XPaths in XAML bindings.

Nothing. Zilch. Nada. Zip. There was one post that made me think that it may well be a bit more difficult that I was expecting.

This post by Karl Hulme almost did what I wanted but not quite. it still wasn’t flexible enough to perform the type of binding I wanted to solve this particular problem, which was, to basically externalise rich tool tip data that was held in an external file, so the client could easily update the data to be shown based on control names on a form. The tool tip had to show not only text, but other rich content that was configured from an XML data source.

So after much head scratching, I came up with what I thought was quite a neat solution. Although it doesn’t solve global warming I think it’s quite a neat solution to the XAML problem. It’s a combination of a Value Converter and a Markup Extension, which allows you to specify XPath bound data in a clean way right in the XAML. The tooltip is then templated using these two classes to display the additional content as well as its original content if any.

(continue reading…)

1 Comment more...

Epic Battles with McAfee

by rob on Feb.23, 2009, under .Net, Development, General

McAfee, Inc.

Image via Wikipedia

What week, I’ve managed about 4 hours of actual development. The problem? McAfee’s on demand scanner.

It all started Monday, whilst I was writing a templated ASP.Net control similar to the inbuilt Logon panel. The difference was that this control respects the privileges of the logged on user, using the Oracle security model that we’re deep into.

Anyway, on using the panel I started getting unrecognised tag errors, and then Devstudio wouldn’t compile the project. At all. So, after a bit of cleaning and the usual go to the dos prompt, i really cleaned the project and tried again. Success.

All the errors went away. Hmm, i thought to myself. must be some cruft from left from the other day when one of the other office staff mistakenly unplugged my PC instead of the electric heater at her feet. Twice.

Any I’d scan-disked the PC and found nothing wrong so off I went merrily coding away. Then odd little errors started creeping in. Tags not recognised, xml schema errors from files I’d not touched for days. It never occurred to me that the On Demand scanner from McAfee could be the culprit. So after blaming myself first for a day, then DevStudio for a day, I started looking at all the other corporate software that was running on the PC. Keep in mind that it takes a day for this because these aren’t the worlds fastest PC’s (the fast ones are on order :) ).

So finally I examine the McAfee On Demand logs. Holy smoke. over 4000 blocked actions in the last hour. Yes I work fast. Either that or there’s a lot of files making up our project ;)

Not only that, but the file it seemed to be scanning was the .ASPX file i just so happened to be working on. I’ll take that as the smoking gun.

So I think I’ve found the culprit, but trying to sort out what to do about it is a whole different story!

Remember that we’re dealing with a corporate IT department. Can I get rid of McAfee? No. I tried that already. Not enough rights. So I ring the IT department. Waivers for developers? modifications to the policies, different virus killer? No, No and NO. So, I’m kind of stuck here. It’s out of my hands now, but given that I’m on a daily rate, this could be getting expensive, and its only when the costs start mounting up that people notice. Nothing I try seems to stop the interference with VS2008, and meanwhile the project is kind of stood still. I haven’t been idle (of course!) I’ve installed a full automated build system whilst I’m waiting for this to get solved, but that’s in a VM where I can guarantee that its running exactly what I want, not what someone else thinks I need ;)

I’ll keep y’all posted.

In the mean time, might I suggest :

1) Don’t use on demand scanners with development environments. Its not worth the hassle. This is the second time McAfee’s bitten me.

2) if you have to use on demand scanners, don’t use McAfee!.

If only real life development was that simple.

 

Reblog this post [with Zemanta]
Leave a Comment more...

Binding and DetailsView

by rob on Feb.11, 2009, under .Net, Development

Since I’m doing more ASP.Net than I’d normally like to admit to, here’s a really useful little snippet that I struggled with earlier. After my google ninjitsu failed me I turned to figuring it out for myself.

Once I’d wiped the sweat from my forehead I came up with a solution. Whew.

Ok, the problem was that I have a typical master/detail gridview & details view on a form which allows the user to select a row in the grid and then edit the details via the DetailsView. So far so good. I managed to get the whole thing hooked up declaratively using ObjectDataProviders so it felt almost like the XAML i know an love ;)

Anyway next on the agenda was the field validation. I’d re-templated the fields on the DetailsView so we’d got DropDownLists showing predefined lists take from the internal DataModel. Life was good. Throw in a few field validators and we’re good to go. Almost.

Since some of the fields on the form were just TextBoxes, I’d added the typical RequiredFieldValidator, but what about the lengths? These text boxes are mapped VarChar columns on the DB, they had an explicit length. I could hand code the length with the MaxLength property but that just means more work should the DB schema change on me.

If this were XAML we’d have it bound up in no time, but all my attempts in ASP failed miserably.

I know that the DataContext – oops sorry (!) – DataItem must be a DataRow from the table the grid was bound to, so there must be a property giving access to the rows columns. Sure enough, there’s the DataRows Table property we can use. Great! Saved! Effectively what I’d like to do would be bind up the MaxLength property to a DataColumns MaxLength propert. Sound simple. something like

<asp:TextBox MaxLength=’<%# Table.Columns["GUR_FORENAME"].MaxLength >’>

Not so fast buster. Unfortunately  the above and all variations I tried didn’t seem to work. Even trying to Bind() to the table didn’t seem to work either

<asp:TextBox MaxLength=’<%# (Bind(“Table”) as DataTable).Columns["GUR_FORENAME"].MaxLength >’>

Since Bind(“Table”) returns object, i thought i was in there! No such luck. Dozens of variations later, magic incantations, a full moon and some voodoo, I finally managed to get it working.

The final version of the binding expression I was after looked like this :

<%# Eval("Table.Columns[\"GUR_FORENAME\"].MaxLength") %>

I’m still freaked out by the fact the whole expression has to be inside the quotes. If Bind() really does return an object what the hell is it? If I had time to spare I’d reflector through this, but unfortunately after spending too long on figuring out how to bind the max length, it’s something that will have to wait.

So, it looks like the ASP binding is a bit more flexible than first thought, and not surprisingly , the standard examples hint at!

Reblog this post [with Zemanta]
Leave a Comment more...

Fix Oracle dot Net…

by rob on Feb.04, 2009, under .Net, Development, Hackery

SAN FRANCISCO - SEPTEMBER 24:  The new Oracle ...

Image by Getty Images via Daylife

…is now up! FixOracle.Net in its first incarnation fixes the type of dodgy Oracle code we’re using on our current project, but since the ‘fixing engine’ is shared between the web site, the winform tool, and the command line tool, when I figure out what casts are missing, I’ll add them too.

In the mean time http://www.fixoracle.net is where you need to go for the absolute best in web design and hot advert-clicking-for-your-friends action.

Well, they’re not going to click themselves.

:)

Reblog this post [with Zemanta]
Leave a Comment more...

Fixing Oracle’s TableAdapters

by rob on Jan.30, 2009, under .Net, Development

Ok, by now you know Oracles table adapters are broken. Just searching on google for a solution turns up a significant number of other people having the same issues. Broken code, bad ODP crashes inside devstudio etc etc etc. Google turns up nothing but bad news when you’re looking for a solution to ease the pain of using .Net and Oracle tools.!

Well, since the fixes are pretty easy to add, I’ve created a little tool to automate the process. Although the fixes are quite simple, they soon mount up when you got more than a couple of TableAdapters that change more than a couple of times during the life of the project. In fact fixing oracle’s bugs starts eating a significant part of your development time, beyond the most trivial projects with one or two adapters. Maybe we should start invoicing them for the time taken to fix their crap code ;)

ok, enough of the idle banter. Since a picture is worth a thousand words here’s a screen grab of the tool to whet your appetite!

orablefixer

Ok, I admit I stole the graphic! Basically this fixes the current crop of problems that the ODT generates when you drag a stored procedure or table to the VS’s Dataset design surface. As an additional ‘fix’ it also makes the Adapters CommandCollection public if you tick the check box.

Making the CommandCollection public means that you don’t have to derive a class from the generated table adapter, or provide another partial class when you want to do things like change the connection string on the fly, or make the commands participate in a transaction.

For those of us unable to use an ORM too or we’re just stuck with Oracle and the default tools for legacy code, this should help a little.

Anyway, I’m going to register a domain for the tool, and provide an online version too, where you upload a source file to fix, and it returns the fixed version. Maybe when there’s a public domain showing how to fix Oracle’s deficiencies, they’ll release a patch for a bug that’s been on metalink for what feels like *eternity*.

Watch out for FixMyOracle.Net coming soon ;)

Leave a Comment more...

Introducing…

by rob on Dec.12, 2008, under .Net, Development

The Munsell color system, showing: a circle of...

Image via Wikipedia

nCode I.T. Limited! Yes, I’ve finally got round to setting up my own limited company. Since it makes more sense from a taxation point of view, and also gives me a platform to launch my own Micro-ISV. Since I’m deeply entrenched in the .Net world at the moment, I thought a bit of word play on the nXXX series of tools (nHibernate, nUnit etc) would have a cool geekiness to it. Anyway, the site basically gives a few details about my skill set & what I’ve been up to, purely for the contracting & outsourcing work, but the final (and as yet unlinked) section will pint to some of the work I’ve been doing outside contracting hours that’s helping me towards the fully fledged Micro-ISV status.

My first commercial product for my Micro-ISV will be a set of Bitmap Effects for .Net 3.5SP1.

This Effect pack will include :

  • Desaturation Effect
    One of the most missed features of WPF is that of greying out interface elements when disabled. when buttons containing bitmap artwork are disabled, the bitmap doesn’t go grey. There are lots of messy kludges and workarounds for this, but this effect addresses that problem completely. As opposed to some of the other available effect this doesn’t just change the element to grey scale it allows you to set a specific saturation level, allowing you to do cool effects like fade out your entire application to grey when it loses focus, kind of like the windows XP shutdown state. Unlike many other average-the-colours type of grey effects this uses the true NTSC colour weights to produce a correct desaturation.
  • Colorize Effect
    This will allow you to change the colour of any element and colorize it any new colour. Colorizing respects the pixels luminance, but changes the colour of each pixel to the new colour you’ve chosen. A simple effect. but very useful for fixing elements to all have the same set of tones.
  • Skin Shade effect
    This is the special one. It allows you to completely re-skin your application (if it is set far enough up the visual tree, i.e. on the top level window) because although it changes the colours, it respects the relationship between them. In other words if you picture the shades used in your application on a colour wheel, they will remain the same relative distances after they’ve changed. This means that if you chose analogous, split compliments, or triadic hues, they will remain that way, but their base hues will be rotated. It sounds much more complex than it actually is! The end result is that as long as your colour set was pleasing to start with, it will remain that way, even after you apply the effect.

Here’s an example of the skin shade effect. Two different ‘skins’ provided by applying the effect right at the top level window. Allowing an almost infinite range of skins is now only 3 lines of XAML away! This is the WPF outlook Hands-On-Lab that the effect has been applied to.

Fancy a rose pink outlook ?

clip_image002

and a fraction of a decimal away are shades of purple.

clip_image002[7]

Notice that although the colours change, the intensity and saturation stay constant. If you have a nice pastel colour set, all you’ll get after applying the effect is more matching pastel colours.

Obviously these effects could be achieved by making sure you set all your element colours to dynamic resources, and then defining lots of resource dictionaries with colour schemes in, then adding an interface to load those schemes. Although this is the traditional way to manage themes (and obviously still has its place) making sure all your elements share the same styles or dynamic resources for colours its a royal pain, and error prone.

Using a single effect like this allows you to define one set of harmonious colours for your application, then get an almost infinite set of harmonious colours at the switch of a floating point value, without ever forgetting to set an elements colour, and also doing away with the resource hit of using dynamic resources for every screen element that you want to change colour.

Another feature of the Bitmap Effects is the ability to selectively apply the effect based on an Opacity value. This allows you to add the bitmap effect to your top level window but still maintain control of which elements actually get affected by the effect right down at the element level.

An example case where you would need this is an application that displays photographs. You really wouldn’t want your grandmothers purple rinse extending across the whole photo just because it was part of the visual tree that the Colorize effect had been applied to! Using a specific value for the Opacity we can exclude elements from the effect. There are samples provided which explain how to do this selective effect application.

All the effects in the library support selective application at the pixel level. Another useful thing this feature allows you to do is maintain a specific colour for your control’s text, and have it excluded from the application of the effects.

I’m currently working on the documentation and samples, but when these bits are done, you can purchase this effects library and get updates, support, and implementation help via the official nCodeFxLib Bitmap Effects site

Enjoy.

Rob

Reblog this post [with Zemanta]
Leave a Comment more...

.Net3.5sp1 RTM?

by rob on Aug.08, 2008, under .Net, Development

A little bird’s told me that the .Net3.5sp1 will be RTM on 11th August! Wonder if the Pixel shader API has been rationalised… Multi-texture here we come ;)

2 Comments more...

System.Windows.Data Error: 19

by rob on Jun.26, 2008, under .Net, Development

Thought I’d brain dump a little problem I came across earlier today. Data Error 19.

Here’s the full error.

System.Windows.Data Error: 19 : Cannot convert ’40′ from type ‘Int32′ to type ‘System.Int64′ for ‘en-US’ culture with default conversions; consider using Converter property of Binding. NotSupportedException: ‘System.NotSupportedException: Int64Converter cannot convert from System.Int32.
   at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
   at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)’

How did I get here? Well, I have a bunch of generated values that come from a data dictionary , they’re generated into classes that contain Key/Value pairs, where the Key is an Int32.

This list is shown in a combo box, and the current value of the combo box is then bound to a CLR value type in a class. The only problem is that the classes CLR Type isn’t an Int32. It’s an Int64.

Now I know the the real fix is to generate a list of values for the combo box who’s type matches the destination bound value of Int64. The trouble is that I don’t always have that type information available. Thing is, I can’t remember any other control having the problem of changing types.

Heck,if you look at the conversion that it’s trying to do, it should be able to cope, converting an Int32 to an Int64 isn’t a narrowing cast, so there should be no problems with overflow. Eitherway, i just want to bind up this stuff and not worry about the types.

So, I wrote a small test app to verify what was going on.

boundVaueTest

Both the slider and the combo box are bound to an internal value, called surprisingly , "BoundValue" that’s declared as an Int64, and there’s a textbox that is then bound the "BoundValue" to show its current value.

 

(continue reading…)

Leave a Comment more...

I’m A Winner …. Again! Or… how to win free stuff with SCRUM :)

by rob on Jun.24, 2008, under .Net, Development

Free Vouchers this time. Apparently I’ve won £100 of vouchers for implementing the Scrum methodology! I have no idea which shops the vouchers are for, only that they’re high street vouchers, so I suppose that’s cool, they could have been for kitchen tiles or something equally as mundane. But, heh, I’m not really doing anything to achieve these awards (like my iPod winning idea), just kind of, well, plugging away at changing things. I guess someone’s starting to listen!

Anyway, we’re kind of a heavily entrenched Waterfall development shop so, I thought I’d liven things up and ignore the people that said we couldn’t do Agile here :) . So I merrily headed off down the Scrum path – having done it before I’m pretty sure by now the shoe will fit.

Friction, damn I thought I was on fire. Straight from 15 years of waterfall into scrum caused friction on a galactic scale – most of it not from the project itself, but the organisation. So, while the project works pretty well, and customer satisfaction skyrockets, the rest of the organisation is playing catch up. Still I guess nothing worth doing is easy. If it wasn’t for the customers complete buy in I don’t think I’d be winning awards, I think I’d be winning P45′s. (for you international readers that’s the short walk to the long unemployment queue…)

So, the best bit is actually that the customer loves the method so much that they’re bending over backwards to keep us using it, so much so that I hear they’re making requests of other projects to be run the same way! So from the customer side I’m starting to shine so much you need sunglasses when you approach my desk, whilst from our side I have dozens, if not hundred of disgruntled waterfallers baying for my blood. Some people simply don’t want to change. Heh, you can’t please all the people all the time.

Here are a few things I’ve noticed using Scrum with non-technical customers that are worth pointing out.

  1. It doesn’t matter how much work you’ve done, if its not on screen its not done.
    You can have web services coming out of your ying yang, and if the customer can’t push a button and see it work you haven’t done it.
  2. It doesn’t matter how your project schedule is organised, if it doesn’t list when visual elements appear, they’re not interested.
  3. Make sure that you’re fully resourced before you start.
    Ok, a bit obvious you may think, but the customer may not be your best friend when it comes to telling them you cant deliver feature X,Y or Z because Johnny Programmer hasn’t joined the project yet.
  4. When organising the project by allowing the customer to prioritise the feature set for the product before generating each sprint, make sure that they’re prioritising Visual Features. They won’t understand anything else.
  5. If the customer is involved in providing data to you, make sure they’re in easy to edit formats like word or excel. Deal with translation or the data conversion yourself, hiding it from the customer. Hint : customers don’t like angle brackets.
  6. Customers like deadlines, make sure that the door swings both ways and provide dates you’d like them to have things ready by. It’s a good idea that keeps them working towards the same goals as you and makes them feel committed to making the product a success.
  7. If you’re having real users testing the application, make sure that its as close to zero defect as possible. Users take great delight in pointing out the obvious like the focus rectangles are missing, they’re not bothered that you haven’t finished that bit yet.
  8. Make sure you have customer identical kit  before you start. Requesting kit wasn’t the problem, the waterfall police ended up delaying requests because we weren’t in the testing period yet.
  9. Prepare to spend a lot of time repeating yourself – especially to the crews on your side. If they’re still in waterfall mode, it will be a while before they ‘get’ it.
  10. Play nicely with others. Although the agile methods typically mean you do everything, it could make whole gaggles of people feel redundant and won’t win you any friends. Even if you can automate all your testing, make sure that your testing dept buys in, and maybe you could even get them involved in learning new testing methods. Who knows they may even want to help provide some code for you. Make sure that everyone feels needed. 

Not an exhaustive list, but things worth keeping in mind if your customer isn’t technical, or they don’t have anyone au-fait with the technology and methodology you’re using.

For the current project I’m using WPF  and scrum – so we’re already 7 years ahead of most of the crowd who are barely breaking free of VB and winforms 1.1 ;)

And,for those of you wondering, yes, you can do LOB applications with WPF. :)

Technorati Tags: ,,,

Leave a Comment more...

Top 10 WPF resources

by rob on Jun.16, 2008, under .Net, Development

As a minor intermission while I put a bit more effort into the WPF article series, I thought I’d list my top 10 favourite WPF and .NET tools.

Ok, here goes!

  1. The amazing free resource that is MSDN
    For top quality articles and all the WPF information you can eat, there is no better place than MSDN (Except of course this blog ;) )
  2. A List WPF Bloggers
    There’s always tons of useful WPF and .Net goodies on the WPF Blogosphere – Check out big names like Rob Relyea , Karl Shifflett, Andrew Smith, Josh Smith, Tim Sneath, Ashish Shetty, Adam Nathan, Chris Anderson, Greg Schechter, Nathan Dunlap and Bea Costa are but a few of my favourites. Many of these guys have great WPF books out on the shelves, and their blogrolls are well worth checking out.
  3. Direct access to the SDK team
    Yes, the WPF SDK team are online, and you can comment on the articles and entries directly on the SDK teams blog!
  4. Expression Blend
    Ok, you can use VisualStudio to edit your UX, but seriously, VS can’t compete with Blend. Download, Learn It, USE IT.
  5. Visual Studio 2008
    By the same token, you can edit code in blend, but you’d have to be a serious masochist. Get hold of VS2008, nothing else comes close. Be amazed at the new feature sets this coding powerhouse gives you. Buy It, Learn It, USE IT with BLEND!
  6. Content Presenters free video resources
    They’re big, they’re excellent quality, and best of all, they’re free!
    Download them and watch them now!
  7. Snoop, Mole and XamlPadX, Kaxaml
    Four absolutely must have tools for helping with the WPF coding experience. While Devstudio does most things, you just cant do without these fantastic four.
  8. The WPF Forums on MSDN
    Absolutely the best place to get your questions answered, and a huge archive of previously solved problems. Before posting remember to search the forum.. most questions have been well covered before!
  9. The Daddy of all WPF sites, WindowsClient.Net
    what doesn’t this site contain. Nothing that’s what. If its not here, you probably don’t need it. ( Even my blog’s on here. Ok, I lied.)
  10. Finally, Nukeation
    Great content (although sometimes corny dialog!) but plenty to digest, and available as podcasts too. Nice job!

 

Well, that filled a little gap for me, while i think about the amount of content i’m going to have to come up with for the next WPF article! <sigh>!

 

Enjoy!

Rob

2 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!