Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Custom CommandParameter
Message
From
22/01/2010 13:15:46
 
 
To
22/01/2010 12:52:47
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01445153
Message ID:
01445509
Views:
25
>>Hi,
>>The aim was to keep the XAML as simple as possible so that the design guys are less likely to get it wrong. But even a stripped down Button looks like this:
<Button>
>>            <Button.Resources>
>>                <res:NewPaperMultiConverter x:Key="NPMC"/>
>>            </Button.Resources>
>>            <Button.CommandParameter>
>>                <MultiBinding Converter="{StaticResource NPMC}">
>>                    <MultiBinding.Bindings>
>>                        <Binding ElementName="txtWidth"  Path="Text" />
>>                        <Binding ElementName="txtHeight"  Path="Text" />
>>                        <Binding ElementName="txtName"  Path="Text" />
>>                    </MultiBinding.Bindings>
>>                </MultiBinding>
>>            </Button.CommandParameter>
>>OK</Button>
And, of course, the order of the bindings is critical. I'm normally using a standard MVVM design but in this case the three parameters don't have a natural mapping to the VM - they are just used to create an object (which is in the VM). I think I'm just going to stick with the pattern and extend the VM to enable the designers to bind the textboxes directly to it - at least they are familiar with that.
>>
>>I had a blurry idea of sub-classing a button with a dependency property that would hold a collection of parameters which could then be used in a generic fashion but I'm not sure the above type of scenario would crop up often enough to warrant the effort.
>
>What class are TextBoxes bound to? Couldn't you just pass that class to the converter?

With the MultiBinding approach they didn't need to be bound to anything - they were just supplying parameters for creating an object (i.e. no existing source). The converter was just throwing out a simple class to hold the parameters:
public class NewPaperParameters
    {
        public double Width { get; set; }
        public double Height { get; set; }
        public string Name { get; set; }
    }
I guess it would be possible to hold an instance of this as a StaticResource and bind the TextBoxes to it and then bind this instance to the Button.CommandParameter. But that would require just as much nous on the part of the designers (and I'm not sure it's doable anyway). I think I'm going to stick with modifying the VM but I'm not happy....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform