Mike Taulty's Blog
Bits and Bytes from Microsoft UK

April 2008 - Mike Taulty's Blog

Blogs

Mike Taulty's Blog

Elsewhere

  • Silverlight 2 - RegisterCreateableType

    I spent about 2 hours trying to figure this out today so I thought I'd just share it here. Mostly, the time lost comes down to Javascript but that's no big surprise :-( Essentially, I'm playing with the HTML Bridge that lets Silverlight .NET code call Javascript code and vice versa. It's all working very smoothly until I want to create an instance of a .NET type ( marked as ScriptableType ) from Javascript. I know that somewhere, there's a method that may be called; createObject createManagedObject createManagedInstance but I can't figure out what the heck it's called and I can't figure out a decent way of figuring that out :-) So...with Silverlight 2 Beta 1 I can confirm that if you have a .NET type such as; [ScriptableType] public class Point { [ScriptableMember] public int X { get; set; } [ScriptableMember] public int Y { get; set; } } and if you've registered this for use from Javascript at some point by calling something like this ( from .NET code ); HtmlPage.RegisterCreateableType( "PointType" , typeof ...
    Filed under: ,
  • Microsoft Office Labs

    Interesting stuff happening up here - I haven't installed these bits yet but they look worth a whirl.
    Filed under:
  • CodeToLive Logos at the MSDN Roadshow

    If you've been to our MSDN Roadshows ( approx 800 of you so far - thanks and thanks also for the feedback which we've gone through for Cardiff and London already ) or if you are planning to come along then you'll know that this year we're using cinemas. This has some serious upsides ( which is why we did it ); Huge screen. Tiered seating ( combined with (1) this means no-one has problems seeing what we're doing :-) ). Comfortable seating ( hey, you're sitting still for maybe 5-6 hours - previous venues have tended to use pretty uncomfortable chairs ). And some downsides; Loading people to/from the cinema takes time. Cinemas tend to have nowhere to sit in their foyers. and possibly some more. One of the things that you might have spotted happening in the cinemas this time around is the displaying of some interesting new logos that have been drawn up in the UK office. Things like this; Now, I have to admit that I was a little sceptical (who, me???!?) around these when I first saw them but I like their use on the...
    Filed under:
  • Silverlight 2 - Build Controls!

    I've been building quite a bit of Silverlight 2 code and the one thing I'd pass on as a piece of advice is "Build Controls ". Even in situations where I've found myself thinking "Oh, this will just be a lump of XAML" I soon find that approach results in a spaghetti-mess of XAML quite quickly and the easiest way is to very quickly split things up in separate controls. Ok, I know this isn't exactly radical advice :-) but it's something that I've noticed very quickly in building Silverlight code.
    Filed under:
  • MEF?

    Very interesting post over here .
    Filed under:
  • Entity Framework Talk at Oracle .NET SIG

    Thanks a lot to the people who came along to my Entity Framework talk at the Oracle and .NET Special Interest Group in London today. As promised, I've uploaded the slides in PPTX and PDF format if you need them for anything.
  • Entity Framework Talk at VBUG Bristol

    Thanks to the people who came along to my talk on Entity Framework at VBUG in Bristol yesterday. I promised that I'd make the slides available and they can be found here for download in PPTX format and PDF format . This was more or less the same talk as I delivered at Southampton the week before so these resources are also relevant.
  • You've got to stop calling it "LINQ" :-)

    <rant strength="veryMild"> A bit of a personal bugbear. I've met a lot of folks who say things like "How do you compare LINQ and traditional data access?" or something along those lines. Please. You've got to stop calling it "LINQ" :-) LINQ is not necessarily anything to do with relational database access. In .NET Framework V3.5 we have; LINQ to Objects LINQ to XML LINQ to SQL ( relational ) "Coming Soon" we have things like; ADO.NET Entity Framework with a LINQ API ( relational ) ADO.NET Data Services where the client code generation pieces take LINQ queries and construct URI's from them. That's at least 5 LINQ pieces from Microsoft already but there are lots of LINQ enabled things going on out there such as; Flickr, Active Directory, SharePoint, etc. etc. etc ( there's a reasonable list up here ) Come on - use "LINQ TO...." when you're talking about LINQ, otherwise everyone (well, me anyway) just gets mixed up :-) </rant>
    Filed under:
  • Databinding XML in Silverlight 2

    I passed across some code to Daniel just last night as he was struggling to get LINQ to XML to read some XML data from a web site ( actually, a web service ) for him. One of the things I miss in Silverlight ( from WPF ) is the ability to naturally bind to XML data and this discussion with Daniel prompted to wonder what I could do about writing classes that make XML data binding more declarative. Approach 1 ( not going to work ) My first instinct was to see if I could implement my own markup extension so that in markup I could write something like; <ListBox ItemsSource="{XmlBinding Source=foo.xml, Path=/foo/item}"/> and then maybe in the template for that ListBox I could use something like; <TextBlock Text="{XmlBinding Path=@value}"/> or something along those lines. However, there's a number of things that would stop me being able to do that; Silverlight doesn't support custom markup extensions like {XmlBinding} above so, naturally, that's really "game over" for this idea. There's also a couple of other...
    Filed under:
  • Entity Framework Talk at NxtGen Southampton

    Thanks a lot to the guys that run NxtGen Southampton and the attendees who came along to my talk on the ADO.NET Entity Framework this evening . I really enjoyed it and hope that you enjoyed it too if you came along - the venue was really interesting ( in what felt like a connecting space between two buildings that are part of a Church ) and thanks a lot to John and Rich who put a lot of effort into getting together a great AV setup and did some sterling work around giving away the essential "swag" :-) If you're around the Southampton area doing .NET development then you should definitely get along to this group. Follow up resources from my talk; http://www.datadeveloper.net ( has a handy set of links including the "Get Entity Framework Beta 3" link ) http://blogs.msdn.com/adonet ( the ADO.NET blog ) http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/08/29/9691.aspx ( Some links from me about Entity Framework ( some are Beta 2 so beware of that ) ) Once again, thanks to NxtGen for inviting...
  • Silverlight 2 - Video, Markers, XML

    I encountered a chap the other day who was building an application which did something like this; Play a video Load a set of times and thumbnail images from an XML file. Highlight the thumbnail images at the point where the video hits the right position. I thought this was a great example of how easy it can be to build solutions with Silverlight 2 ( regardless of whether Expression Encoder can already do some/all of this for you automatically ). Starting with a UI, I might have; < UserControl x:Class ="SilverlightApplication12.Page" xmlns ="http://schemas.microsoft.com/client/2007" xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls ="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" > < Grid x:Name ="LayoutRoot" Background ="White" > < Grid.RowDefinitions > < RowDefinition Height ="7*" /> < RowDefinition Height ="3*" /> </ Grid.RowDefinitions > < MediaElement x:Name ="media" Source ="{Binding VideoUri}" HorizontalAlignment ="Center...
    Filed under:
  • Silverlight 2, Databinding to the MediaElement.Position property

    In a word, don't :-) MediaElement.Position is very attractive because it's pretty common to display some UI to show an indicator displaying where you're up to within a particular video. MediaElement.Position is of type TimeSpan and it's a DependencyProperty so it looks ripe for binding. However, it won't work. I've asked around and one of the reasons why it doesn't work is that it's actually quite a high resolution value ( I'm advised of the order tracking at 100ns intervals ) and so if you databound to it then you'd be getting an awful lot of updates. So...if you need to display where you're up to within a video then it might be advisable to use a Storyboard that goes from 0 to the duration of the video and animate some property (e.g. value of a thumb on a slider) based on that. Alternatively, you could use a timer and poll the Position value every so often.
    Filed under:
  • Silverlight 2, Buttons in ListBoxes

    Just something that I came across recently. If I have a ListBox like this; <Grid x:Name= "LayoutRoot" Background= "White" > <ListBox ItemsSource= "{Binding}" > <ListBox.ItemTemplate> <DataTemplate> <Button Content= "Click Me" Click= "OnClick" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> and I write code behind it like this; public partial class Page : UserControl { public Page() { InitializeComponent(); this .Loaded += new RoutedEventHandler(Page_Loaded); } void Page_Loaded( object sender, RoutedEventArgs e) { this .DataContext = Enumerable.Range(1, 9); } void OnClick( object sender, EventArgs args) { } } Then I find it difficult to click on the buttons in the ListBox as below; That is - if I click on the button in the selected item (red squiggle) then that seems to work fine. If I click on the button within a non-selected item (yellow highlight) then it doesn't fire its Click event. It only works as a button when I select that item first ...
    Filed under:
  • Silverlight 2 - Getting to the ListBoxItems in a ListBox

    If you've got a Silverlight UI like this; < Grid x:Name ="LayoutRoot" Background ="White" > < ListBox ItemsSource ="{Binding}" x:Name ="lstNumbers" > < ListBox.ItemTemplate > < DataTemplate > < StackPanel Orientation ="Horizontal" > < Rectangle Width ="100" Height ="50" Fill ="Red" ></ Rectangle > < TextBlock Text ="{Binding}" /> </ StackPanel > </ DataTemplate > </ ListBox.ItemTemplate > </ ListBox > </ Grid > and you set up the DataContext so that the binding works as in; public partial class Page : UserControl { public Page() { InitializeComponent(); this .Loaded += new RoutedEventHandler(Page_Loaded); } void Page_Loaded( object sender, RoutedEventArgs e) { this .DataContext = Enumerable.Range(1, 9); } } then there might be circumstances where you want to get hold of some element of the UI for each item in the list like our ListBoxItem, StackPanel, Rectangle, TextBlock here. You might write something like; void Page_Loaded( object...
    Filed under:
  • Silverlight - Dynamically Loading an Assembly

    Just something that someone asked me about today so sharing here. Imagine that you want to define a portion of your Silverlight application but leave some other piece to run time. For example - a calculation engine or perhaps something more complicated like a piece of UI with interaction. You can dynamically load up a .NET assembly in Silverlight at runtime, pull out known types from it and interact with them just like you would in any other .NET application. I made my example as simple as possible. I defined a core UI which looks like this; The idea is that the red bit is the "host" and the yellow bit is for the plug-in editor. I define an interface to live between my host and my plug-in editor; public class TextEventArgs : EventArgs { public string TheText { get; set; } } public interface IEditUI { UIElement GetControls(); void SetText( string text); event EventHandler<TextEventArgs> TextChanged; } and then an implementation of that which I put into an assembly called Implementation which is not referenced...
1 2 Next >