9

グリッドスプリッターで苦労しています。RowDefinition.Height以下に示すように、依存関係プロパティをモデルの clr プロパティにバインドしました。

    <Grid.RowDefinitions>
        <RowDefinition Height='{Binding Path=Height, Mode=OneWay}' />
        <RowDefinition Height='*' />
    </Grid.RowDefinitions>

これは、GridSplitterが使用されるまでは正常に機能します。で行の高さを手動で変更するGridSplitterと、バインディングが新しい固定サイズに置き換えられます (バインディングが削除されます)。

GridSplitter でサイズ変更できる 2 つの行を作成する方法や、clr プロパティ/バインディングに従って高さを変更する方法についてのアイデアや回避策はありますか?

4

1 に答える 1

18

Height問題は、ソース プロパティのタイプが double であり、タイプが でRowDefinition.Heightあることだと思いますGridLength。コンバーターを使用すると、TwoWay で動作します

<Grid.RowDefinitions>
    <RowDefinition Height="{Binding Path=Height,
                                    Mode=TwoWay,
                                    Converter={StaticResource DoubleGridLengthConverter}}"/>
    <!--...-->
</Grid.RowDefinitions>

DoubleGridLengthConverter

public class DoubleGridLengthConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return new GridLength((double)value);
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        GridLength gridLength = (GridLength)value;
        return gridLength.Value;
    }
}

更新
ここにサンプル アプリケーションをアップロードしました: http://www.mediafire.com/download.php?pgibb205d65596q

下部にRowDefinition.Height値を入力して を設定し、TextBoxRowDefinition.HeightGridSplitter

于 2011-03-10T13:10:02.180 に答える