2016-07-06 16 views
0

多値コンバータを使用して行の高さを取得しています。しかし、私は高さのバインディング(スヌープを介して見られる)で次のエラーが発生します。行の定義のためにコンバータが機能しません。

System.Windows.Dataエラー:5:BindingExpressionによって生成された値は、ターゲットプロパティに有効ではありません。値= '33 .44444 'MultibindingBindingExpression:ターゲット要素は' RowDefinition 'です。ターゲットのプロパティが '高さ'(タイプ 'GridLength')

多くのグーグルでも、この問題を解決できませんでした。誰でもこの問題を解決するのを助けてくれますか?

私の行の定義:

<Grid.RowDefinitions> 
          <RowDefinition> 
           <RowDefinition.Height> 
            <MultiBinding 
    Converter="{StaticResource HeightConverter}"> 
             <Binding Path="Height" 
RelativeSource="{RelativeSource AncestorType=controls:TestControl, 
Mode=FindAncestor}" UpdateSourceTrigger="PropertyChanged"></Binding> 
             <Binding Path="MR" 
    RelativeSource="{RelativeSource AncestorType=controls:TestControl, 
    Mode=FindAncestor}" UpdateSourceTrigger="PropertyChanged"></Binding> 
             <Binding Path="BR" 
    RelativeSource="{RelativeSource AncestorType=controls:TestControl, 
    Mode=FindAncestor}" UpdateSourceTrigger="PropertyChanged"></Binding> 
            </MultiBinding> 
           </RowDefinition.Height> 
          </RowDefinition> 
          <RowDefinition Height="Auto"></RowDefinition> 
          <RowDefinition Height="*"></RowDefinition> 
         </Grid.RowDefinitions> 

私の身長コンバータコード:

public object Convert(object[] values, Type targetType, object 
    parameter, CultureInfo culture) 
    { 
     var TH = (double)values[0]; 
     var TR = (double)values[1]; 
     var BR = (double)values[2]; 

     var per = TR + BR; 
     var per2 = (TR/per)*100; 

     return (int)(per2/TH)*100; 
    } 

おかげ&よろしく

+0

は 'ActualHeight'作業にHeight''よりも良く結合していますか? 'Height'は一般的に実行時に変更されないので、' Binding'はそれまでに起きることはありません。 –

答えて

0

あなたのConverterからあなたGrid Heightためintを戻ってきています。

がSystem.Windows.Controls.RowDefinition要素の計算された高さを取得し、又はSystem.Windows.GridLengthを設定します。それはGridLength

public System.Windows.GridLength Height { get; set; } 
Member of System.Windows.Controls.RowDefinition 

MSDN

から以下を参照の概要であるべきですSystem.Windows.Controls.RowDefinitionで定義されている行の値。

戻り値:行の高さを表し

System.Windows.GridLength。デフォルト値は1.0です。


戻りGridLengthあなたのコンバータから以下のような、

return new GridLength(0, GridUnitType.Star); // Or 
return new GridLength(per2/TH)*100); 
関連する問題