Contact Me

Contact Us
For an informal discussion

Everyone's business is different. Our business is software - ask where we can help.
eMail: john at appsolo.com

Archive for May, 2010

Nested Resource Dictionaries a no-no

Monday, May 31st, 2010

Having spent way too long chasing down a XAML problem, the lesson learned is that you can’t nest resource dictionaries in Silverlight – so don’t. Consider the following code:

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Assets/Button.xaml"/>
                <ResourceDictionary Source="Assets/ScrollBar.xaml"/>
                <ResourceDictionary Source="Assets/ToggleButton.xaml"/>
                <ResourceDictionary Source="Assets/ScrollBar.xaml" />
                <ResourceDictionary Source="Assets/ScrollViewer.xaml"/>
                <ResourceDictionary Source="Assets/ComboBox.xaml"/>
                <ResourceDictionary Source="Assets/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

Here I kept getting errors to do with not being able to set the resource image thumb17 Nested Resource Dictionaries a no no‘Source’ property (opposite). The problem lay with the ComboBox.xaml styling containing a further merged ResourceDictionary. Apparently, that’s a big no-no.

Styling a Combo-box in Silverlight

Wednesday, May 26th, 2010

A major selling-point of XAML/Silverlight/WPF is the whole lookless nature of the controls. We can style the appearance (image thumb11 Styling a Combo box in Silverlightand behaviour) of controls as much as we like – even easier with Expression Blend. However, knowing how to do this (even in Blend) is no small matter. Take my experience of making a combo-box change the default blue highlight that appears when the mouse rolls over the control. 

As you can see (opposite), I’ve achieved some initial styling by changing the simplest of things – the ItemTemplate. This is easily done (even in VS) by creating a Data Template (in this case with two TextBlocks) and assigning it to the ItemTemplate dependency property of the combo-box:

<ComboBox x:Name="cbxKeys" ItemsSource="{Binding Data, ElementName=taxKeyDomainDataSource}">
            		<ComboBox.ItemTemplate>
            			<DataTemplate>
            				<StackPanel Orientation="Horizontal">
            					<TextBlock Text="{Binding TaxKeyName}" TextWrapping="Wrap" TextTrimming="WordEllipsis" FontSize="16" FontWeight="Bold"/>
            					<TextBlock TextWrapping="Wrap" Text="{Binding Author.AuthorName}" TextTrimming="WordEllipsis"
            						FontStyle="Italic" FontSize="16" Margin="5,5,0,0"/>
            				</StackPanel>
            			</DataTemplate>
            		</ComboBox.ItemTemplate>
            	</ComboBox>

 

This is actually quite powerful in the sense that it has an immediate and visible effect. Now let’s dig deeper. As with all Silverlight/WPF controls, there is plenty of behind-the-scenes XAML handling both appearance and behaviour. A property often overlooked is the ItemContainerStyle. The role of this property is to act as a container for each ComboBoxItem (or ListBoxItem). This lets you make such simple changes as the margin inside of which each item in the contained. But the real power lies in the ControlTemplate of the ListBoxItem for the ItemContainerStyle. Yes, you read that right. Normally, when we think of a ControlTemplate you associate it with a particular control and a reasonably radical alteration of its appearance (and behaviour). In this case though, we’re looking at the ControlTemplate for the rendering of each item in the ItemsControl (the base class for ListBox and Combo-box). Now this is a little like open-heart surgery so break out Expression Blend (unless you talk fluent XAML).

image thumb12 Styling a Combo box in SilverlightWhen you crack open a copy of the Control template for ComboBoxItem (see how opposite), you’ll see that there are a number of elements making up the container. The most obvious of these is the contentPresenter – it’s into here that each ListBoxItem (or ComboBoxItem) gets placed. Now notice fillColor and fillColor2 – these humble rectangles actually represent the colour that appears as you mouse-over the items or select (an) item(s)image thumb13 Styling a Combo box in Silverlight. So the Fill property for these Rectangles is where to go to change the appearance of the items as you navigate over them.

Now, you’d think that was that – but what about the blue that appears when the ComboBox is collapsed as in the first screen shot above. This isn’t controlled by the control template of the ListBoxItem in the ItemContainerStyle property (repeat that 10 times!). Long story short – the structure and appearance of the collapsed ComboBox is image thumb14 Styling a Combo box in Silverlight managed by the control template for the ComboBox itself (and not the ListBoxItem we’ve been talking about). By editing (the poorly named) template as shown opposite, you’re changing the fundamental behaviour of the ComboBox. image thumb15 Styling a Combo box in Silverlight You can see this fundamental makeup of the control by looking at the components of the control template (below). The highlight is the ContentPresenterBorder. Though innocently named, it contains the essential structure of the collapsed ComboBox. Note the BtnArrow (draw in a vector path, of course) and the ContentPresenter that holds the TextBlock to display the text of the collapsed ComboBox.

But what we’re after is the DropDownToggle ToggleButton that the whole collapsed control. This is what appears in blue when we mouse over. However, this behaviour is managed by the Visual State Manager (VSM) which is for another day. Thankfully, I don’t want to change its behaviour – just its appearance. This appearance (and the behaviour) is managed by an assigned style to the control. This is where Blend bows out and we drop to XAML in the resource editor. Digging through the various styles and trying to navigate around the massive VSM code, we find a few Rectangles named BackGroundOverlay and BackGroundOverlay2. Checking the Fill property of these Rectangles tells me that they are blue. Just bind the Fill property to my own StaticResources and hey presto, we dump the blue.

Now I don’t feel too bad having wasted spent an evening sorting through the XAML!

Kudos to Blacknight Support

Wednesday, May 26th, 2010

I would like to give big Kudos to the support staff at our hosting site www.blacknight.com who have done a great job assisting us with our hosted deployment of our Silverlight 4 RIA services SQL SERVER 2005 .NET 4.0 application. It’s a complicated business for developers and hosters alike. Their speedy response to our technical issues is greatly appreciated. Thanks guys and keep up the good work.

P

Wiring UP an Insert Stored Procedure to a RIA based application c#, VS2010

Thursday, May 20th, 2010

The stored Procedure I am using is one that creates a Taxonomical Key containing a root Node with an Arc emanating from the Root Node.

(more…)

EF DomainDataSource binding to SQL table-join

Saturday, May 15th, 2010

There are some conveniences brought by Entity Framework (EF). One is the provision of navigation properties for entities. Essentially, these provide easy access to entities (or collections thereof) in associated tables. (more…)

Wiring UP an Insert Stored Procedure to a RIA based application c#, VS2010

Thursday, May 13th, 2010

The stored Procedure I am using is one that creates a Taxonomical Key containing a root Node with an Arc emanating from the Root Node.

(more…)

Windows Live Writer and Code Syntax styling

Thursday, May 13th, 2010

As a Silverlight developer, you’re likely to need to blog occasionally on your app. I use Windows Live Writer (WLW) to handle all my posting – even with WordPress’s super-easy UI, I like the desktop shortcuts inherent in WLW – keyboard shortcuts (e.g. Ctrl-K for links), drag ‘n drop images (including auto uploading). There are also some neat plugins that make WLW even better. One I really like is Code Snippet by Leo Vildosola – takes you IDE code and keep it just as is in your post. For example, here’s method from a recent app:

   1: private void trvArcs_SelectionChanged_1(object sender, SelectionChangedEventArgs e)

   2:         {

   3:             Node n = (Node)trvArcs.SelectedItem;

   4:             TaxFullDbDom tdc = new TaxFullDbDom();

   5:             EntityQuery<Arc> query =

   6:             from c in tdc.GetArcsQuery()

   7:             where c.ArcID == n.ArcID

   8:             select c;

   9:             LoadOperation<Arc> loadOp = tdc.Load(query);

  10:             this.arcDataForm.ItemsSource = loadOp.Entities;

  11:             arcDataForm.AutoEdit = true;

  12:             arcDataForm.CurrentIndex = 0;

  13:         }

image thumb Windows Live Writer and Code Syntax stylingWLW also taps into your WordPress (WP) tags list so there’s no WP involvement needed – though confusingly WLW calls tags categories in its parlance.

Another useful plugin is Twitter Notify. Simple – after publishing a post, this sends a tweet notifying your followers of the new post.

For my money anything that keeps the posting process in WLW if worth a few minutes. WLW is very much an underappreciated desktop app – maybe not everything is best server-side icon wink Windows Live Writer and Code Syntax styling

image1 thumb1 Windows Live Writer and Code Syntax stylingUpdate:

Things move pretty fast! Code Snippet showed some issues with a blank line inserted between each line as you might see above. Looking at this further, it seems SyntaxHighlighter by Alex Gorbatchev has a well respected Javascript library which does a very nice job on syntax colour coding etc. – for a growing stable of languages (e.g. XML and C# in my case). SyntaxHighlighter Evolved has subsumed this library and packaged it as a WordPress plugin. Still with me? Well, byinstalling this plugin to your hosted WP, it (almost) automatically prettifies any code in your posts – from within WordPress, that is. Doing so is real easy – just wrap your clipboarded code in a [language] tag – e.g. place [language] before your C# code and [/language] at the end of the code, where language is something like csharp. You won’t see it until you Preview or Publish the post but it’s a high quality output.

Now, to integrate with Windows Live Writer. Over on CodePlex, there’s a WLW plugin called PreCode. This works with SyntaxHighlighter (remember, you installed that on WP) to wrap your offline WLW edited post in the necessary tags so that when it gets server-side and published by WP, SyntaxHighlighter will do its thing – and give you beautiful formatted code like this:

private void trvArcs_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Node n = (Node)trvArcs.SelectedItem;
            TaxFullDbDom tdc = new TaxFullDbDom();
            EntityQuery<Arc> query =
            from c in tdc.GetArcsQuery()
            where c.ArcID == n.ArcID
            select c;
            LoadOperation<Arc> loadOp = tdc.Load(query);
            this.arcDataForm.ItemsSource = loadOp.Entities;
            arcDataForm.AutoEdit = true;
            arcDataForm.CurrentIndex = 0;
        }

image thumb6 Windows Live Writer and Code Syntax stylingNow the funny thing here is that (at least in my WP install), the above code shows up nicely rendered (by the SyntaxHighlighter Javascript library) on the excerpts post listing. However, occasionally, when you click through to the full post, we lose the formatting. Answers on a postcard, please. Scott Hanselman has more details on integrating the Javascript into any blog template so when I get time. Come to think of it, it could be a side-effect of the WP-Cache plugin. Seems it might also be rectified by setting the ‘Load All Brushes’ checkbox in the WP SyntaxHighlighter plugin.

Update on SyntaxHighlighter in WP:

Having lucked out with what I thought was a perfect solution with PreCode and SyntaxHighlighter, I found another WLW plugin (SourceCode plugin)that purports to work with SyntaxHighlighter – and well, it does but my occasional loss of formatting persists on the full post page. So, not a SyntaxHighlighter issue then. I prefer this plugin over PreCode – it’s lighter and easier to work with.

    private void trvArcs_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
            {
                Node n = (Node)trvArcs.SelectedItem;
                TaxFullDbDom tdc = new TaxFullDbDom();
                EntityQuery<Arc> query =
                from c in tdc.GetArcsQuery()
                where c.ArcID == n.ArcID
                select c;
                LoadOperation<Arc> loadOp = tdc.Load(query);
                this.arcDataForm.ItemsSource = loadOp.Entities;
                arcDataForm.AutoEdit = true;
                arcDataForm.CurrentIndex = 0;
            }

Addendum:

Finally, to Silverlight. This takes a little more patience but thanks to Tim Heuer and Erno de Weerd, and their Silverlight for WordPress and SLforWP.dll plugins respectively, the process works as you can see below. Tim’s plugin is a straight-forward WLW install, and Erno’s is just a dll to dump in the plugins folder of WLW. Erno also describes another plugin – this time for you WP install – to help it with the MIME mapping for XAP files. You’ll also need write access to the upload folder on your WP install but it’s all good.

There’s more work to do though as I suspect the MIME mapping isn’t working but I’ll update when I diagnose the problem and post properly.

Moving RIA Data Based Applications from one Machine to another Machine

Tuesday, May 11th, 2010

Oftentimes you want to move an application from one machine to another when developing across different machines for local development (if the database is not on an accessible Database Server) with VS2010. When Moving an application developed using RIA services tools and a connected SQL Server Database from one machine to another there are a few things to look out for.

1. Ensure that your target Database is as similar to your new target database as you can make it. You can use the the Generate Database from Model option (right click on the .edmx screen as shown below) to write a script of the Database that is connected to the current application and displayed in the .edmx screen.

 

edmxshot thumb Moving RIA Data Based Applications from one Machine to another Machine

This Generates an SQL script which you can run in the new database. But be aware that Views that you have used will be scripted as Tables. So you might have to change the script just before running it in the new target database. Just CREATE TABLE to CREATE VIEW should do it.

2. Edit the Web.config file to update the Connection string to point at the new database.

3. In the new location for the application you will have to delete the existing entities from the edmx and then create them again. I think there must be a reference to the original connection string somewhere (in one of the partial hidden parts grrr, that just popup when things go horribly wrong).  Provided the table and field names are the same  in the new target database (which they should be as you have exported the table definitions from the edmx in the first place) it should repopulate well.

Just some ideas. It worked for me so it should work for you if you have to do.

Now deployment of a developed application on a hosted server that’s another thing.

P.

RIA Services Resources

Tuesday, May 11th, 2010

Update: RIA Services gone gold with version 1.0 (late May 2010)

1145.RIAServicesDiagram RIA Services ResourcesRIA Services is a step-change from WCF and for those migrating to internet-hosted data access frameworks. Since RIA only came of age following its release with Silverlight 4 and the significant enhancements to VS2010 that support it, it’s safe to say that it isn’t the most familiar animal to many.
Various show-tours seem to parade endlessly on the net showing carefully choreographed walk-throughs of tightly scripted RIA services handling – ‘Just drag the data source you like onto the canvas and lo, a datagrid miraculously binds itself to the necessary data’. And hey, here’s a Pager that cleverly knows to share the same data source. And look, no code – XAML rules. Well, yes but it all gets a bit ’samey’ after a time and once you start tackling a real-world task, you find that the showy stage show is just that – an act.
Now, to be fair, RIA Services is here to stay and that’s a good thing. However, taken with Entity Framework (bye, bye LINQ-to-SQL), a generous update to Silverlight and a crash-course in WCF, RIA Services carries a big stick and it takes some getting used to.
But RIA Services looks like the ‘next best thing’ for data access across the wire. And having had a quick look at WCF, that’s probably a good thing. Naturally, WCF is at the root of it all but RIA acknowledges that we don’t like heavy plumbing and provides a well-balanced abstraction. So having sat through way too many videos and walk-throughs that ever so neatly avoid real code, here is my collection of resources for learning RIA that pick up where that hand-holding leaves off.

  • Ronnie Saurenmann – Principal Architect MS has an excellent 45min video on RIA Services. Covering Entity Framework, DomainDataSource, Validation (including custom) and more. Not for the novice but good when you know enough to feel totally lost icon smile RIA Services Resources
  • Contoso Book Club – John Papa. Delivered at the SL4 launch keynote, this is a good worked example (source & starter project provided). The post walkthrough while mostly VS2010 tooling-driven, is well annotated and the example itself is rich enough to be credible. image thumb 39 RIA Services Resources
  • Building A Data-Driven Expense App with Silverlight 3 – Jonathan Carter and Terry Adams. Sorry, don’t know the authors but this MSDN piece (while pre-RIA RC – and man, MS like to change thing last minute) does an admirable job of walking through the code needed to wire up a DomainContext, looking at the role of Domain Operations in the generated DomainContext class, DomainDataSource objects to project data into new controls (like Data Form) – and they do it in code. Heck, I’ll appreciate the fancy VS2010 control handling later, but not until I understand what going on under the hood.
  • WCF RIA Services (MSDN) – Though this refers to pre-release RIA, it looks fine. Maybe I’m maturing but recalling how I recoiled every time I resorted to MSDN, I now find it more appealing. When it comes to a complex, multi-faceted and highly integrated framework like RIA, I really appreciate the carefully crafted (though often clinical) language of the technical writers at MSDN. This doc is very thorough and watch a good few videos before approaching it!
  • Silverlight 4 WCF RIA Services Line of Business Application Hands-On Lab – Sascha Corti & Ronnie Saurenmann. Over 100 pages of hands on explanation and guidance, starter & final solutions, published Dec ‘09 so targets SL4 – this is complete, thorough and well-written.

Deploying RIA services, SL4 & .NET 4.0 on shared hosting

Thursday, May 6th, 2010

I am deploying a WCF RIA application to a shared windows server 2008 instance operated by Blacknight and this is my side of the story so far.

Most shared Hosting environments do not offer great support for direct deployment from VS 2010 (or earlier). Yeah nothing is that simple! So I have to deploy using ftp (which must be setup also – Thanks John).

So when deploying RIA servicesbased application  you have two choices …..

1. Compile the assemblies locally (properties Copy Local to true .dlls in my day) to the bin folder and then when you deploy via FTP up to the server they go up there also. Which assemblies will be on the shared Host and which ones won’t is guess work I’m afraid as it will depend on a combination of what you deploy and what is already installed by the administrators of the hosted site. So I presume it depends on what your Hosting support has enabled in .NET 4.0 and the GAC?

2. Install RIA services on the GAC (not an option unless your kind tech support person will do it for you) and oh God it’s been a while since I looked at that GAC!!

Also you usually have to complete the roundness of IIS (IIS 7.0 in this case) and I’m no expert here but you’ll need to set up your Virtual directory to point at the directory that you upload to and then the fun starts. At this stage the Silverlight xap will most likely download to the Browser when the web application is loaded.

Saurabh Pant’s blog on RIA Services RC although now out of date (already icon sad Deploying RIA services, SL4 & .NET 4.0 on shared hosting )) is worth a read for hints on what then goes wrong.

I have gone with the first approach above and this is the error returned to the Silverlight client.

LoadError thumb Deploying RIA services, SL4 & .NET 4.0 on shared hosting

The ASP forms authentication works on a local deployment but is throwing an error on the GetUser() function also Even with the forms authentication turned off. So it might be over to my nice technician for the GAC update.

PS: OK. From reading around the subject matter

http://community.discountasp.net/showthread.php?p=39129

http://openlightgroup.net/Blog/tabid/58/EntryId/55/RIA-Services-Windows-Authentication-amp-GetUser-Error.aspx
and
http://forums.silverlight.net/forums/t/176108.aspx
and
http://blogs.msdn.com/saurabh/archive/2010/03/16/ria-services-application-deployment.aspx

it would appear that there are many possible pitfalls between IIS 7.0 (which we only have limited control over as it is Hosted) ASP.NET authorisation, RIA deployment (believe it or not the most control over) and Database management and Access (again Hosted and limited control/access due to Blacknight web based Database manager app). I could be wrong but the ASP.NET authorisation database is hidden from the developer. The sources say that you should use customised authorisation when working with hosted servers. When you create a Silverlight Business app in VS 2010, it automatically creates the infra-structure to support the ASP.NET authorisation.

So as we are going to handle user validation through our SQL Server 2005 database anyway, I’ll create a Silver Navigation template and introduce RIA services to that and then only have to deal with the second error above.

I’m reminded of the AI programming paradigm. Computing concepts work well in the Lab but the real world (wide web) is a complicated place!!.

If things do not improve, I think we will end up deploying on our own server.

PP.

2 pages

latest news

UI Flow

Posted on Tuesday, 16th April, 2013

Often, we use wire-framing or mock-up tools (like the good guys at Balsamiq) to help communicate design ideas between developers as well as to clients. However, there is a need for something more efficient to aid communication of possible user interface flows through our emerging application. This communication is for internal use typically and doesn’t [...]

Testimonials

Excellent design skills

Posted on Sunday, 2nd May, 2010

We at Taxonomy.ie are happy to be associated with Appsolo and look forward to further work together.

follow me

twitter facebook delicious

AppsoloLtd. VAT No. IE97548691 - Copyright © 2010.