Archives for the ‘.Net’ Category

Silverlight – Element is already the child of another element

Mike Talbot of Alterian has a clever way of taking most of the guesswork figuring out which piece of XAML is misbehaving, by progressively stripping out child nodes until the error is gone.
In his own words:
When the file has a problem it starts to prune out nodes in the XAML one XML node at a [...]

Binding to DatePicker in Caliburn.Micro

I’m running Silverlight, and I have a DatePicker control which I wish to bind automatically.
Recipe

Caliburn.Micro.ConventionManager.AddElementConvention(Of DatePicker)(DatePicker.SelectedDateProperty, "SelectedDate", "SelectedDateChanged")
Caliburn.Micro.ViewModelBinder.Bind(_reportFilterVm, Me.ReportFilter, Nothing)

Passing arrays to SQL statements safely

SQL Parameters only accepts scalar values. What if you wanted to pass an array as an IN criteria?
Here’s a workaround, without using stored procs. Just IFormatter magic.
You will be able to to this:

Dim ids(0 to 3) as integer
ids(0) = 32
ids(1) = 34
ids(2) = 42
ids(3) = 48
statement = SqlFormatter.Format("SELECT * FROM Persons WHERE PersonId in {0:f0}", [...]

Why Microsoft Lightswitch is not MS Access.

There is a great deal of concern among developers that Visual Studio Lightswitch will dumb down programming. Donald Belcham, for example, suggests that Lightswitch is going to be like MS Access with all it’s bad practices.
To the professional developers that read this blog (most of you I’m guessing), prepare to move your hatred and loathing [...]

SwivelPanel/Card Flip with Silverlight

John Papa has a nice Silverlight trigger to perform a “Card Flip”.
However, he didn’t show how it is possible to trigger the card flip on the reverse side.
Unfortunately, this can’t be done in Xaml. Fortunately, it only requires a few lines of code, and modification of the trigger.

[...]

element is already the child of another element domaincontext

The best way to troubleshoot this is by stripping of elements from your xaml on by one.
In my case, I had a ChildWindow which hosted a domain context. I don’t know why by this is sufficient to trigger the error.

<Grid.Resources>
<!– Commenting out the offending [...]

Silverlight Development – Required Background Reading

If you are an experienced developer, the guides on Silverlight.net are not as useful as the following: there are useful snippets that I come back for reference again-and-again, and they build the right conceptual idea of EF in your head.
Silverlight WCF Service Client

A pattern for Silverlight’s asynchronous operations

Silverlight can only invoke web operations asynchronously. Normally this would have led to a mess of logic. However, with anonymous methods, the problem can be managed. People who are familiar to Ruby blocks would see the similarity.
In the VB.net example below, I have a function AllocateSerialNumber which (eventually) returns a string.

Imports System.ServiceModel.DomainServices.Client

Dim myDomainContext As [...]

ASP.net 4.0 Silverlight Hosting Tweaks

Having strange 404 Not Found problems with your Silverlight deployment when it all works fine in your development environment?

This is what my hosting provider had to change to support WCF Silverlight deployments. Hope it helps you too.

Silverlight Navigation and Logon Forms

When a Silverlight page is shown, there are background threads that are still running. One of them is the user authentication service. This means that you don’t know whether the user is authorized to view the page or not, at least not until the operation has completed.

To be safe, you should not start any domain service (i.e. set AutoLoad=”False”) unless WebContext.Current.User.IsAuthenticated.

You also have to wire up a bunch of event handlers to monitor user’s status.

Styling combo boxes with new Silverlight 4 themes

Wonder why doesn’t your Cosmopolitan themed application pick up the styling for comboboxes, etc like the one in the demo?
In the App.xaml add the following section

<ResourceDictionary Source="Assets/Styles.xaml"/>
<– The following section is required for themes to work –>
<ResourceDictionary Source="Assets/Brushes.xaml"/>
<ResourceDictionary Source="Assets/CoreStyles.xaml"/>
<ResourceDictionary Source="Assets/SDKStyles.xaml"/>
<ResourceDictionary Source="Assets/ToolkitStyles.xaml"/>

Databinding ComboBox in Silverlight DataForms

Read the article below if you wish to bind text to a static list on comboboxes.
Read this article if you wish to fill the ComboBox with a list fetched from a database
Say we have a text field for “Gender”, which we want to set to either “Male” or “Female”, the basics of setting up the [...]

Troubleshooting Silverlight 4.0 and WCF Deployment problems

There’s plenty to read on the internet how to manually troubleshoot deployment issues.
However, none try to automate this. Here’s a little troubleshooting script. It worked for me (up to a point). Feel free to extend this if you encounter further issues.
(Update: also have a look at WCF issues that only my hoster could address)

<%@ [...]

Silverlight equivalent of CSS list menus

Using CSS to style HTML list items as menus is considered good fashion, and I wondered if there is an equivalent in Silverlight.
Here is an inlined example. It can be refactored into a Style and stored away in the Resources section (see MSDN example)

<ListBox Height=”100″ Name=”ListBox1″ Width=”120″>
[...]

Silverlight Navigation Framework and Authentication

The Silverlight Navigation frameworks allows application developers to use URLs as shortcuts to specific screens within an application. (This idea of using URLs as a pointer to a specific application resource is not foreign to a web developer, but is certainly a new concept for most application developers).
However, it is the responsibility of the developer [...]

MonthCalendar SetDayState in VB.net

I had to resort to Interop code, because MonthCalendar.UpdateBoldedDates recreates the window, and messes up the current date ranges.
First, declare some Interop functions and data structures

Const MCM_SETDAYSTATE As Integer = &amp;H1008

<StructLayout(LayoutKind.Sequential)> _
Structure MONTHDAYSTATE
Dim dw As [...]

SQL Server Error Creating User Instance

Fellow Australian Dave Gardiner points out there is a patch available from Microsoft where SQL Server Express would not start up a user instance over Remote Desktop.
Thanks!

Has the JVM design been holding back Java?

Update:Looks like the post has been linked from DZone. Tell me what you think? What kind of projects would you choose Java applets over Flash or AJAX?

After all these years, Java’s applet has not seen much adoption, while Flash continue to gain mindshare. Applets suffer from slow start up times, crashing browsers, heavy resource usage. [...]

Browsers will Rule Mobile Devices

Five years ago, when prototyping some apps for PDAs, I’d never consider HTML + javascript. This is because there are enough form factor issues as well as browser incompatibilities to keep one awake all night.
Things have changed.
WebKit seems to have gained ground in the mobile space, giving compatibility a much needed shot in the [...]

A concrete proposal for inlining JavaFX

Jan Erik calls me the “high IQ” type. Unfortunately, I think he means “impractical” and “living in an invory tower”.
The idea of a inlining JavaFX script is actually a smaller and incremental goal. It is practical and is achievable. It will allow people who don’t have the JavaFX SDK to experiment with the technology, within [...]