1

这应该很简单,但我被卡住了!如何在代码中创建以下多重绑定并将其应用于给定的行定义:

<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
        <RowDefinition>
            <RowDefinition.Height>
                <MultiBinding Converter="{StaticResource MyMultiConverter}">
                    <Binding ElementName="obj1" Path="x"/>
                    <Binding ElementName="obj2" Path="y"/> 
                </MultiBinding>
            </RowDefinition.Height>   
        </RowDefinition>
 </Grid.RowDefinitions>

谢谢!

4

1 回答 1

0

你去:

//Create binding
var binding = new MultiBinding
{
    Converter = new MyMultiConverter()
};
binding.Bindings.Add(new Binding("x") { ElementName = "obj1" });
binding.Bindings.Add(new Binding("y") { ElementName = "obj2" });

//create RowDefinition
var definition = new RowDefinition();
//set binding on HeightProperty
definition.SetBinding(RowDefinition.HeightProperty, binding);

//'myGrid' is the name of the grid instance
//add RowDefinition to grid
myGrid.RowDefinitions.Add(definition);

为了能够在代码隐藏中处理网格,您向网格添加一个名称:

<Grid Name="myGrid">
    ...
</Grid>
于 2015-04-29T17:57:15.187 回答