Mike Taulty's Blog
Bits and Bytes from Microsoft UK

July 2007 - Mike Taulty's Blog

Blogs

Mike Taulty's Blog

Elsewhere

  • Silverlight 1.1 Alpha Refresh - Name Things :-)

    If you're writing code that dynamically generates "things" (Storyboards and so on) with the V1.1 Alpha Refresh then don't forget to give them a name (i.e. from a XAML perspective this is typically what you set with "x:Name" (using the convention of x there)) and from a code perspective this is DependencyObject.NameProperty otherwise I think you'll get failures. I've been using Guids where I don't have a genuine name for an object. You might even in the C# 3.0 world have pseudo-code (not in front of a compiler as I write this) like; public namespace XamlExtensions { public static class XamlExtensions { public static void MakeUniqueName( this DependencyObject o) { string guid = Guid.NewGuid().ToString(); o.SetValue(DependencyObject.Name, guid.ToString()); } } }
  • VS 2008 Beta 2 - LINQ to SQL

    I had my first play with LINQ to SQL in VS 2008 Beta 2 today. Things that I "noticed" that were new (i.e. this is not a definitive list, purely what I spotted) when I created code using the LINQ to SQL designer. My derived context now has a Database attribute on it - thanks! Saves me setting it in the connection string. My derived DataContext now has extensibility methods on it. This is the new way of hooking into the Insert, Update, Delete process for different entities. So, if I have just one entity Customer then I now get partial methods InsertCustomer, UpdateCustomer, DeleteCustomer on my DataContext and if I want to take part in the insert/update/delete process then I can "complete" these methods to do so. Previously, this feature relied on you "naming your methods correctly" so I view this use of partial methods being a big helper here. There's also an OnCreated for the context. My entity classes also have a big set of partial methods on them to facilitate extensibility. It looks like we've got OnLoaded...
  • Toolset.Refresh

    Just uninstalling my VS 2008 Beta 1 and installing; VS 2008 Beta 2 Silverlight 1.1 Alpha Refresh Expression Blend 2, August Preview Silverlight Tools Alpha for Visual Studio 2008 Silverlight 1.1 Alpha Refresh SDK
  • Silverlight V1.1: Trying to build a simple drag-and-drop capability

    I wanted a very simple kind of drag and drop ability in Silverlight V1.1 and I struggled to build it. Basic procedure might be to build a Canvas that does something like; Capture mouse down on a FrameworkElement Watch for mouse drag. As the mouse drags, create a graphical representation of the FrameworkElement being dragged Watch for mouse up. Take the original Visual and either move it within its original container or perhaps reparent it if it got dragged into the bounds of some new container. I got fairly stuck at point (3). If I had a VisualBrush then this would perhaps be relatively easy in that I could create a brush from the original FrameworkElement, create a rectangle of similar size and paint it with that brush. However, there's no VisualBrush . So, I just figure I'll put a requirement onto whatever FrameworkElement that wants to be draggable so that it implement ICloneable so that I can ask it to copy itself and I'll drag a copy of it around. However...a control copying itself becomes a bit tricky. As...
  • Silverlight V1.1: Scrolling Picture List Box

    I built a very basic listbox control that will display pictures. It looks like this; and will scroll through a list of items. I define it in XAML like; < ctl:PictureListBox Width ="600" Height ="200" Canvas . Left ="20" Canvas . Top ="140" RadiusX ="10" RadiusY ="10" > < ctl:PictureListBoxItem Source ="img1.jpg" ></ ctl:PictureListBoxItem > < ctl:PictureListBoxItem Source ="img10.jpg" ></ ctl:PictureListBoxItem > < ctl:PictureListBoxItem Source ="img13.jpg" ></ ctl:PictureListBoxItem > < ctl:PictureListBoxItem Source ="img16.jpg" ></ ctl:PictureListBoxItem > < ctl:PictureListBoxItem Source ="img1.jpg" ></ ctl:PictureListBoxItem > < ctl:PictureListBoxItem Source ="img10.jpg" ></ ctl:PictureListBoxItem > < ctl:PictureListBoxItem Source ="img13.jpg" ></ ctl:PictureListBoxItem > < ctl:PictureListBoxItem Source ="img16.jpg" ></ ctl:PictureListBoxItem > </ ctl:PictureListBox > It's very basic in the sense that...
  • Neil's IEeee VSTS Project on CodePlex

    I noticed that Neil has uploaded a new version of his IEeee browser plug-in that lets you easily submit defects about a web-site into Visual Studio Team System straight from the browser itself. He's also got some new Work Item Controls for grabbing screenshots as you submit items. If you're in the UK and you're working with Team System then this is a great blog to follow along as those "guys" at the top of the page are the people who have responsibility for selling Developer Tools (VSTS, VS, Expression) in the UK and so knowing the names and being able to get in touch by email should provide you with a great resource :-)
  • Dream Job?

    Sounds pretty cool to me
  • VS 2008 Beta 2

    Visual Studio 2008 Beta 2 is done. The details are up here: http://msdn2.microsoft.com/en-gb/vstudio/default.aspx I've been working with Beta 1 since that came out and I've found it to be pretty solid so I have high hopes for Beta 2 and it looks like that's reinforced by there being a Go Live license for it and the .NET Framework V3.5. < Now downloading ... >
  • Silverlight V1.1: Loaded fires more than once

    This is possibly "by design" (i.e. I don't know) but I've noticed that if I reparent a Silverlight control from one Canvas to another then its Loaded event fires for a second time when it is reparented. So, with a user control such as; public class UserControl1 : Control { public UserControl1() { System.IO.Stream s = this .GetType().Assembly.GetManifestResourceStream( "SilverlightProject6.UserControl1.xaml" ); this .InitializeFromXaml( new System.IO.StreamReader(s).ReadToEnd()); this .Loaded += new EventHandler(UserControl1_Loaded); } void UserControl1_Loaded( object sender, EventArgs e) { } } with a XAML definition of; < Canvas xmlns ="http://schemas.microsoft.com/client/2007" xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" Width ="640" Height ="480" Background ="White" > </ Canvas > if I then have a Page that uses this as in; < Canvas x:Name ="parentCanvas" xmlns ="http://schemas.microsoft.com/client/2007" xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" Loaded ="Page_Loaded" x...
  • Silverlight V1.1 - Changing the XAML Page

    When your Silverlight control loads, it loads up some XAML. It's most likely that this comes from a file specified by the source parameter. For instance; function createSilverlight() { Sys.Silverlight.createObjectEx({ source: "Page1.xaml" , parentElement: document.getElementById( "SilverlightControlHost" ), id: "SilverlightControl" , properties: { width: "100%" , height: "100%" , version: "0.95" , enableHtmlAccess: true }, events: {} }); } It might be that at some later point you want to switch from Page1.xaml to Page2.xaml in order to avoid having to put everything into a single XAML file. You can do this but (I'm very reliably informed) not from managed code right now and, furthermore, you can't even initiate the sequence from managed code. If you try it from managed code (using the HtmlObject object) then you'll get an error saying something like "No, you can't do that right now". So, you need to do it from Javascript and just change the source property; function OnChangePage() { document.getElementById( 'SilverlightControl...
  • Silverlight V1.1 "Tab Like" Control Thingy :-)

    I built this little control for Silverlight today so I thought I'd share (note, it doesn't have to be orange). Essentially, it's like a tab control but the "tabs" on the left hand side slide across to the right (and vice versa) to reveal content as in; So, the XAML that actually uses this looks something like; < Canvas x:Name ="parentCanvas" xmlns ="http://schemas.microsoft.com/client/2007" xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" Loaded ="Page_Loaded" x:Class ="SilverlightProject1.Page;assembly=ClientBin/SilverlightProject1.dll" xmlns:ctl ="clr-namespace:SilverlightProject1;assembly=ClientBin/SilverlightProject1.dll" Width ="640" Height ="480" Background ="White" > < ctl:TabControl Width ="640" Height ="480" > < ctl:TabItemControl HeaderText ="One" >< Canvas Background ="Yellow" /></ ctl:TabItemControl > < ctl:TabItemControl HeaderText ="Two" >< Canvas Background ="Green" /></ ctl:TabItemControl > < ctl:TabItemControl HeaderText ="Three" ><...
  • Alex Homer and the Enterprise Library

    Phil kindly invited me along to the Manchester Vbug meeting tonight where Alex Homer was delivering a session on using the Enterprise Library with ASP.NET. Alex did a great job and I found the whole thing really interesting. I haven't really spent much time with the Enterprise Library . I played with the startings of it when it was just the "Logging Block", the "Data Access Block" and I think there was the Online/Offline Block and perhaps also (or am I just making this up now) the Updater Application Block (which I think went on to be reborn as ClickOnce). The bit that caught my eye most was the Validation part of the library which can do some reasonably smart things in terms of performing property and method validation on an object instance for you including composite rules built out of boolean operators. All good stuff :-)
  • Silverlight V1.1 - More on the Dodgy Topic of Controls, Resources and So On

    Following up on this post , I took this a little further in that I added support for loading resources from either multiple separate files or from embedded resources within the assembly and took away the requirement to make an explicit call as I had previously in InitResources . I changed that base class ResourceControl to be; public class ResourceControl : Control { private enum ResourceType { File, AssemblyResource } private class ParseResult { public ResourceType Type { get; set; } public string ResourceLocation { get; set; } public string ResourceKey { get; set; } } static ResourceControl() { resources = new Dictionary< string , Dictionary< string , DependencyObject>>(); } protected static Dictionary< string , DependencyObject> LoadResourcesFromStream( Stream stream) { Dictionary< string , DependencyObject> loadedResources = new Dictionary< string , DependencyObject>(); XmlReader reader = XmlReader.Create(stream); try { if ((reader.MoveToContent() == XmlNodeType.Element) &&...
  • Silverlight V1.1 - More about controls and complex content

    Because of this , it seems to me that it's a bit tricky to build controls :-) Also, it seems that it's a bit tricky to marry up designers and developers. For example, say you want to build the FancyColouredPathControl control. So, you stick a new control into your Silverlight project and (for argument's sake) you add properties to your control for Background and Path as in; public class FancyColouredPathControl : Control { public FancyColouredPathControl() { System.IO.Stream s = this .GetType().Assembly.GetManifestResourceStream( "SilverlightProject4.FancyColouredPathControl.xaml" ); mainCanvas = (Canvas) this .InitializeFromXaml( new System.IO.StreamReader(s).ReadToEnd()); } public Path Path { get { return path; } set { path = value ; if (path != null ) { mainCanvas.Children.Remove(path); } path.Width = mainCanvas.Width; path.Height = mainCanvas.Height; mainCanvas.Children.Add(path); } } public Brush Background { get { return (mainCanvas.Background); } set { mainCanvas.Background = value ; } } public new double...
  • Silverlight V1.1, Controls and "Complex Content"

    If you're building controls with V1.1 then take care about trying to set their value. For example, you might build a control Foo with a property of type string called Label . Then, when you use this in XAML you'll be able to do; < myNS:Foo Label ="Hello" /> and that's all fine. But, if you build a property of type Brush for instance called Colour then you might try and do; <myNS:Foo Colour="Red"/> and I think that'll work but I also think that you'll get stuck if you try and go for a more "long-handed" form of; < myNS:Foo > < myNS:Foo.Colour > < SolidColorBrush Color ="Red" /> </ myNS:Foo.Colour > </ myNS:Foo > in that (AFAIK) this won't work on custom controls.
1 2 Next >