October, 2007

  • Cloudy in Seattle

    .Net Framework Library Source Code

    • 2 Comments

    Scott Guthrie, a GM in the division I work in (Developer Division) has just made a great post about how Microsoft will be releasing the source code of the .Net Framework libraries along with Visual Studio 2008

    I know, I know, the majority of you that develop using one of the .Net techologies use reflector, so this may not seem like a big deal but consider the demo that Scott walks through that shows the integration of debugging, source and symbols.  This is such a win for .Net developers.

  • Cloudy in Seattle

    Change in Behavior of AdornerProvider Activate and Deactivate Methods

    • 1 Comments

    We made a change post Visual Studio 2008 (Orcas) Beta 2 in the way the AdornerProvider.Activate() and AdornerProvider.Deactivate() methods are called. 

    In the past you could assume that the Activate() and Deactivate() methods would be called exactly once per AdornerProvider instance. 

    This is no longer true, in Visual Studio 2008 RTM, it will be possible that for a given AdornerProvider instance, the Activate() and Deactivate() methods will be called multiple times.  I had to update my TechEd samples to accomodate this.

  • Cloudy in Seattle

    Problems with Nested ItemsControls

    • 1 Comments

    As we approach the end of the Orcas project schedule (Visual Studio 2008) I've been doing some app building in order to help validate the quality of the product that we are shipping. 

    In doing so, I ran into a WPF bug that actually ended up costing me a fair amount of time. 

    I was trying to display a collection of teams where each team had a collection of tasks.  I used an ItemsControl to display the teams and inside the ItemTemplate for each team, I had an ItemsControl that displayed the tasks.

    I got the teams showing up but only the first task for the first team showed up.  I went on trying to debug this, using TextBlock set to various binding expressions so that I could see the data as DataBinding would see the data.  After a few hours of finding nothing wrong with my code, I hit the web and found that I had hit on a bug. 

    In fact, I found 2 bugs in this area:

    https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2202842&SiteID=1

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1275132&SiteID=1

    There is an illustrative code sample in the forum posting so I didn't bother adding my own in this post.  I did want to raise awareness to this issue as there is a workaround (reference the DataTemplate for the ItemTemplate from resources) and I hope I can save someone some time.

  • Cloudy in Seattle

    How to get my XAML to show up in the WPF Designer: IMultiValueConverter

    • 1 Comments

    Recently I made a post about how to deal with Application.Current at design time.  I thought I'd follow that up with another example of why your XAML may not show up in the WPF Designer (Cider) due to assumptions that are not true at design time.

    In this case, we're talking about implementing an IMultiValueConverter for a MultiBinding:

        public class SampleConverter : IMultiValueConverter
        {
            public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                string text = (string)values[0];
                Brush backgroundBrush = (Brush) values[1];
                return text + backgroundBrush.ToString();
            }
            (. . .)
        }

    In my sample, I am using this SampleConverter in a ControlTemplate that is defined in Application.Resources:

            <ControlTemplate x:Key="ReadOnlyTextBlockTemplate" TargetType="{x:Type TextBox}">
                <ControlTemplate.Resources>
                    <loc:SampleConverter x:Key="SampleConverter"/>
                </ControlTemplate.Resources>
                <Border BorderBrush="Black" BorderThickness="1">
                    <TextBlock>
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource SampleConverter}">
                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Text"/>
                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Background"/>
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </Border>
            </ControlTemplate>

    This all works fine at runtime but at design time, I fail to load with the error:

    Error 1 Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.String'. C:\Users\jnak.REDMOND\Desktop\MultiBindingExample\MultiBindingExample\App.xaml 13 21 MultiBindingExample

    If you attach another instance of Visual Studio and debug into this, you'll find this:

    Ahh, I made an assumption that is always true at runtime but is not always true at design time.

    There are situations like this where some of our hookup is still being worked out and your code needs to handle this in order to work correctly in the designer.

    The simple fix here is to deal with this exception being thrown or check the type before trying to cast it (or use a construct such as "as" and check for null).

    -- Project is attached for full repro.

  • Cloudy in Seattle

    Bug in Finding Metadata Assemblies

    • 1 Comments

    As it turns out, we have a bug in finding metadata assemblies that will be in Visual Studio 2008 RTM.  I described how we find and load metadata assemblies in a previous post and the bug pertains to the situation where:

    • The main assembly is being loaded from the GAC
    • The project where the main assembly is being loaded is not referenced by the project
    • You have your main and metadata assemblies in a folder defined in the AssemblyFolders in the registry

    The main line scenarios where this will be true is:

    • Loading metadata while populating the items in the Choose Toolbox Items (i.e. for ToolboxBrowsableAttribute)
    • Instantiating a control from the toolbox the first time in a project (the reference isn't made yet)

    Workaround

    In order to handle all of the situations (note that your customers may GAC your assemblies on you provided your assemblies are strong named) you need to provide 2 sets of design time assemblies (in your AssemblyFolder): 

    • MyAssembly.Design.dll and/or MyAssembly.VisualStudio.Design.dll
    • MyAssembly.dll.Design.dll and/or MyAssembly.dll.VisualStudio.Design.dll

    Sorry for the inconvenience, at least there is a reasonable workaround.

Page 1 of 1 (5 items)