3つの変数に依存する行の高さにコンバーターを作りたいと思います。それらのうちの2つはビューモデルからのものであり、1つは定数ストリングです。私はこのためにMultiValueConverterを作ったが、明らかにRowDefinition.Height値を設定していない。RowDefinitionの高さでのマルチバインド
コードは次のようになります。
<RowDefinition Name="Row1">
<RowDefinition.Height>
<MultiBinding Converter="{StaticResource MyConverter}">
<Binding Path="PropertyFromViewModel1" />
<Binding Source="{StaticResource DataGridName}" />
<Binding Path="PropertyFromViewModel2" />
</MultiBinding>
</RowDefinition.Height>
</RowDefinition>
コンバータが動作している、それが(文字列として)適切な値を返します。多値コンバータの
コード:
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 "";
}
私はIValueConverter前に使用し、それがRowDefinisionのHeightプロパティに取り組んが、イマイチを多ましました。
私たちにもMultiValueConverterを見せてください。 –