user746571
user746571

Reputation: 33

Multibinding in RowDefinition Height

I want to make converter for row height, that is dependent on 3 variables. Two of them are from view model and one is constant string. I made MultiValueConverter for this, but obviously its not setting the RowDefinition.Height value.

The code looks like this:

<RowDefinition Name="Row1">
    <RowDefinition.Height>
        <MultiBinding Converter="{StaticResource MyConverter}">
            <Binding Path="PropertyFromViewModel1" />
            <Binding Source="{StaticResource DataGridName}" />
            <Binding Path="PropertyFromViewModel2" />
        </MultiBinding>
        </RowDefinition.Height>
    </RowDefinition>

Converter is working, it returns proper values (as strings).

Code for multivalue converter:

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (!((values[0]) is bool))
            throw new ArgumentException("First argument 'value' must be of type bool");
        if (values[1] == null)
            throw new ArgumentException("Secound argument must be diffrent then null");
        if (!((values[2]) is bool))
            throw new ArgumentException("Third argument 'value' must be of type bool");

        var showParkedTransactionDataGrid = (bool)values[0];
        var datagridName = values[1].ToString();
        var isCustomerDiscountShowed = (bool)values[2];
        if (showParkedTransactionDataGrid)
        {
            if (datagridName == "ProductListDataGrid")
            {
                return isCustomerDiscountShowed ? "306" : "336";
            }
            else if (datagridName == "ParkedTransactionDataGrid")
            {
                return "*";
            }
        }
        else
        {
            if (datagridName == "ProductListDataGrid")
            {
                return "*";
            }
            else if (datagridName == "ParkedTransactionDataGrid")
            {
                return "0";
            }
        }
        return "";
    }

I used before IValueConverter and it was working on RowDefinision Height property, but multibinding isnt.

Upvotes: 3

Views: 1612

Answers (1)

Emond
Emond

Reputation: 50672

The Height is of type System.Windows.GridLength

Make sure you return that from the converter.

EDIT

And, by the way, the converter is not very well designed! It is completely dependent on the naming of the controls. It will be very hard to find errors when renaming the controls.

You should consider another way of doing this.

Upvotes: 4

Related Questions