View Issue Details

IDProjectCategoryView StatusLast Update
0001889NoesisGUIC# SDKpublic2021-03-15 17:10
ReporterDavidYawCSpeedAssigned Tosfernandez 
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Product Version3.0.9 
Target Version3.0.12Fixed in Version 
Summary0001889: MultiBinding's Binding list gets overwritten by list from XAML
DescriptionI have a subclass of MultiBinding, which sets a couple properties by default: It sets a converter, and it sets the first binding in the collection. Any bindings specified in XAML should be added to the list (this is what WPF does), but instead the entire list is replaced, and my default first binding is removed.

There is a workaround for this, so this is 'minor' severity.
Steps To Reproduce
public class FancyMultiBinding : MultiBinding
{
    private static Logger logger = LogManager.GetCurrentClassLogger();
    
    private static Binding CreateFirstBinding()
    {
        Binding bind = new Binding();

        bind.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Window), 1);
        bind.Path = new PropertyPath("Resources[FooBar]");

        return bind;
    }

    public FancyMultiBinding()
    {
        // If this is specified in XAML, don't make the developer re-type 
        // the converter and first binding every time. Apply them by default. 

        this.Converter = new FancyMultiConverter();
        this.Bindings.Add(CreateFirstBinding());
    }
}

<TextBlock FontSize="40" Foreground="Pink">
    <TextBlock.Text>
        <local:FancyMultiBinding ConverterParameter="TESTING">
            <Binding Path="Width" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Window}}"/>
            <Binding Path="Height" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Window}}"/>
        </local:FancyMultiBinding>
    </TextBlock.Text>
</TextBlock>


When I set a breakpoint in FancyMultiConverter.Convert, the array 'values' has the Width and Height values, but not the string result of the FooBar resource.

When I implement the same thing in WPF, the array of 'values' in the converter has all three binding results: The one applied in the constructor, plus the two specified in XAML.

---------------------------------------------------------------------------------------------------------------

I do have a workaround for this, but it's not pretty. I apply the default first binding in the constructor, which works if it's the only binding, and in ProvideValue, I check if it's still there, and re-apply it if it was erased by the list in XAML.

public class FancyMultiBinding : MultiBinding
{
    private static Logger logger = LogManager.GetCurrentClassLogger();
    
    private static Binding CreateFirstBinding()
    {
        Binding bind = new Binding();

        bind.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Window), 1);
        bind.Path = new PropertyPath("Resources[FooBar]");

        return bind;
    }

    Binding defaultFirstBinding;

    public FancyMultiBinding()
    {
        // If this is specified in XAML, don't make the developer re-type 
        // the converter and first binding every time. Apply them by default. 

        this.Converter = new FancyMultiConverter();

        defaultFirstBinding = CreateFirstBinding();
        this.Bindings.Add(defaultFirstBinding);
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        if (Bindings[0] != defaultFirstBinding)
        {
            Bindings.Insert(0, defaultFirstBinding);
        }

        return base.ProvideValue(serviceProvider);
    }
}
TagsNo tags attached.
PlatformAny

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2021-01-18 20:45 DavidYawCSpeed New Issue
2021-01-18 20:46 DavidYawCSpeed Steps to Reproduce Updated View Revisions
2021-01-18 20:47 DavidYawCSpeed Steps to Reproduce Updated View Revisions
2021-01-18 20:47 DavidYawCSpeed Steps to Reproduce Updated View Revisions
2021-01-18 20:48 DavidYawCSpeed Steps to Reproduce Updated View Revisions
2021-01-19 17:11 jsantos Assigned To => sfernandez
2021-01-19 17:11 jsantos Status new => assigned
2021-01-19 17:11 jsantos Target Version => 3.0.10
2021-02-10 18:29 jsantos Target Version 3.0.10 => 3.0.11
2021-03-15 17:10 jsantos Target Version 3.0.11 => 3.0.12