Binding by Convention x:Name="Close" Bug?

Sep 30, 2010 at 2:48 PM

Hi,

I have a button on my UI named "Close" and a parameterless method of the same name in my VM. When it comes to firing the click event the convention fails within the fuction below;


public
 static object[] DetermineParameters(ActionExecutionContext context, ParameterInfo[] requiredParameters)
        {
            var providedValues = context.Message.Parameters.Select(x => x.Value).ToArray();
            var values = new object[requiredParameters.Length];

            for(int i = 0; i < requiredParameters.Length; i++)
            {
                var value = providedValues[i];........

 

The requiredParameters collection contains 1 ParameterInfo (Because of the guard CanClose) and the Message.Parameters is empty.

Because of this the Close method doesn't get fired. Is this a bug?

Coordinator
Sep 30, 2010 at 3:35 PM

Can you send me a repro please? Thanks.

Sep 30, 2010 at 4:39 PM

Hi,

On creating a repro I noticed a knock on effect from the x:Name="Close" problem which I'll try to explain.

Events do not fire for subsequent elements that are bound using the default binding.

In the repro, there are three buttons in a stack panel, if the "Close" button is moved first in the panel, all three will not call their method on the VM. If it its moved to last in the panel, the first two buttons call the VM method.

 

http://cid-044ad885bcfe52a6.office.live.com/self.aspx/.Public/CM%5E_NamingProb.rar

 

Coordinator
Sep 30, 2010 at 5:19 PM

The problem is that you named your method "Close" and there is a method on the base class called "CanClose" which takes one parameter and gets picked up by convention as the guard to your Close method. I advise not naming the method Close :) Also, there is a method called TryClose which might do what you really want.