Home Dashboard Directory Help
Search

WPF Nested Markup Extension Bug by Winston Pang


Status: 

Active


23
0
Sign in
to vote
Type: Bug
ID: 509234
Opened: 11/9/2009 2:21:17 AM
Access Restriction: Public
1
Workaround(s)
view
15
User(s) can reproduce this bug

Description

I recently was implementing a custom Markup Extension, however I stumbled across a problem, and was faced with an error message in Visual Studio.

The problem is also faced before in VS2008, and is still not fixed in VS2010 BETA 2, this blog post highlights the issue:

http://www.hardcodet.net/2008/04/nested-markup-extension-bug

Details
Sign in to post a comment.
Posted by Microsoft on 7/25/2012 at 9:58 PM
The WPF team has recently reviewed this issue and will not be addressing this issue as at this time the team is focusing on the bugs impacting the highest number of WPF developers. If you believe that this was resolved in error, please reactivate this bug with any necessary supporting details.
Posted by wiyosaya on 3/1/2012 at 12:26 PM
I also ran into this trying to bind to ancestors in conditions on a MultiDataTrigger

Here's the xaml:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding RelativeSource={RelativeSource, Mode=FindAncestor,
            AncestorType={x:Type ComboBoxItem}}, Path=IsSelected}" Value="false" />
        <Condition Binding="{Binding RelativeSource={RelativeSource, Mode=FindAncestor,
            AncestorType={x:Type ComboBox}}, Path=IsDropdownOpen}" Value="true" />
    </MultiDataTrigger.Conditions>
    <Setter Property="Visibility" Value="Collapsed" />
</MultiDataTrigger>

The explicit property/value syntax is a work-around - this is not the exact replacement xaml for the above, but it is similar-
<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition>
            <Condition.Binding>
                <Binding>
                    <Binding.RelativeSource>
                        <RelativeSource Mode="FindAncestor" AncestorType="{x:Type ComboBoxItem}"/>
                    </Binding.RelativeSource>
                    <Binding.Path>IsSelected</Binding.Path>
                </Binding>
            </Condition.Binding>
            <Condition.Value>true</Condition.Value>
        </Condition>
        <Condition>
            <Condition.Binding>
                <Binding>
                    <Binding.RelativeSource>
                        <RelativeSource Mode="FindAncestor" AncestorType="{x:Type ComboBox}"/>
                    </Binding.RelativeSource>
                    <Binding.Path>IsDropDownOpen</Binding.Path>
                </Binding>
            </Condition.Binding>
            <Condition.Value>false</Condition.Value>
        </Condition>
    </MultiDataTrigger.Conditions>
    <Setter Property="Visibility" Value="Visible" />
</MultiDataTrigger>
Posted by Mark Heath on 2/21/2012 at 7:37 AM
I ran into this, trying to use a custom IValueConverter inside a DataTemplate. Following simplified app.xaml:
    <Application.Resources>
        <my:CallFillBrushConverter x:Key="callFillBrushConverter" />
        <DataTemplate x:Key="callTemplate">
            <Rectangle Fill="{Binding, Converter={StaticResource callFillBrushConverter}}" />
        </DataTemplate>
    </Application.Resources>

will produce the following error:

Unknown property 'Converter' for type 'MS.Internal.Markup.MarkupExtensionParser+UnknownMarkupExtension' encountered while parsing a Markup Extension.

Workaround of using the property syntax does work however:
        <DataTemplate x:Key="callTemplate">
            <Rectangle>
                <Rectangle.Fill>
                    <Binding Converter="{StaticResource callFillBrushConverter}"/>
                </Rectangle.Fill>
            </Rectangle>
        </DataTemplate>
Posted by Gazzzzzzer on 9/9/2011 at 9:37 AM
Can you please provide an update to this bug.

Using the workaround will be changing the way we implement our code (consistency issue) in places.

This has been an issue for a number of versions of Visual Studio , developers have been reporting this since 2006!

Please can someone look at this issue an include a fix for future versions, service packs, patches!

Thanks,
Gary
A frustrated Developer
Posted by JonSlaughter on 4/18/2011 at 10:19 AM
Wow, I guess this will never get fixed?!?!?!
Posted by Christian Walther on 3/14/2011 at 9:21 AM
For the record, I am having a similar experience in Visual Studio 2010 SP1 that may or may not be a symptom of the same problem.

I have a custom markup extension ("Localize") and pass a {Binding} to it as a constructor argument, e.g.

<TextBlock Text="{loc:Localize {Binding ElementName=testtb, Path=Text}}"/>

As jods observes, this compiles and runs fine, but breaks the designer, where "break the designer" means that the designer occasionally fails to reload with the following exception:

NullReferenceException was thrown due to document error:
Object reference not set to an instance of an object.
at Microsoft.Expression.DesignModel.InstanceBuilders.ExpressionCache.Validate(IInstanceBuilderContext context, List`1& sites)
at Microsoft.Expression.DesignModel.Core.ViewNodeManager.InvalidateInternal(List`1 invalidRoots, Boolean forceValidateExpressionCache)
at Microsoft.Windows.Design.Platform.ViewProducerBase.ApplyUpdate(Delta delta)
at Microsoft.Windows.Design.Platform.ViewProducerBase.IncrementalRebuild(DocumentTreeManager tree, Damage damage)
at Microsoft.Windows.Design.Platform.ViewProducerBase.UpdateView(DocumentTreeManager tree, Damage damage)
at Microsoft.Windows.Design.DocumentModel.ViewProducer.UpdateView(UpdateDamageArguments args)

This specifically happens when I add or remove an object to/from the XAML. Merely changing an attribute value usually works. Closing and reopening the XAML editor window gets it back into a working state.

It is unlikely to be a problem in my own code, as it also happens when the LocalizeExtension completely ignores its constructor argument, while replacing the argument by a literal string fixes it. Using other markup extensions than {Binding}, e.g. {StaticResource} or {x:Null}, also triggers it.

Putting the markup extension in a separate assembly does not help - I see no difference.

Using property element syntax does not work in the {Binding} case because when I try to assign a <Binding> to the property of the LocalizeExtension that corresponds to the constructor argument, it thinks that I want to bind that property, which doesn't work because it is not a dependency property. That is not what I want, I want to pass the actual Binding object to the markup extension.

The problem does not occur when designing in Expression Blend 4, only in Visual Studio.
Posted by jods on 2/25/2010 at 8:28 AM
Using the VS 2010 RC, having an extension (e.g. {x:Type}) as a constructor parameter to a custom MarkupExtension breaks the designer (but compiles and runs).
Posted by Microsoft on 11/10/2009 at 1:30 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted.
Sign in to post a workaround.
Posted by Thomas Levesque on 11/16/2010 at 3:00 PM
2 possible workarounds :

- use property element syntax rather than attribute syntax

- declare the markup extension in a separate assembly