1

Closed

Provide Parameter.Owner property protected access

description

The Parameter.Owner property is marked as private, so a derived class is not able to access the Owner ActionMessage, thus cannot invoke an availability update.

To make clear why such feature is desirable, consider the following interface for a view-model:
public interface ISelector
{
        bool CanSelect(IEnumerable items);
        void Select(IEnumerable items);
}
The Select method is used in an ActionMessage, whose Parameter.Value is databound to a Selector.SelectedItems property. Something along these lines:
<UserControl>
   <!-- ... some more XAML -->
   <ListBox x:Name="listBox"/>
   <!-- ... some more XAML -->
   <Button>
    <i:Interaction.Triggers>
      <EventTrigger EventName="Click">
        <cm:ActionMessage MethodName="Select">
          <cm:Parameter Value="{Binding ElementName=listBox, Path=SelectedItems}"/>
        </cm:ActionMessage>
      </EventTrigger>
    </i:Interaction.Triggers>
  </Button>
   <!-- ... some more XAML -->
</UserControl>
The action guard is re-evaluated only when the parameter value changes (just once), but I would like it to be re-evaluated whenever either the parameter changes OR the collection changes.
To do this, I need to subclass the Parameter class, but the private access to the Owner property forced me to use reflection on a private field...
        /// <summary>
        ///     Gets the action message  owner.
        /// </summary>
        /// <returns>The action message owner.</returns>
        private ActionMessage GetOwner()
        {
            return (ActionMessage)typeof(Parameter).GetProperty("Owner", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this, null);
        }
If the Owner property was actually protected, I could reach the goal without this dirty hack, and the AdvancedParameter class could be used event in partial-trust.
Closed Sep 2, 2013 at 4:33 AM by EisenbergEffect
Fixed

comments