Wpf GridSplitter 替换 row.height 属性上的绑定

发布于 2024-10-21 03:06:48 字数 438 浏览 10 评论 0原文

我在网格分割器方面遇到了困难。我已将 RowDefinition.Height 依赖属性绑定到模型的 clr 属性,如下所示。

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

在使用 GridSplitter 之前,这一切都可以正常工作。当使用 GridSplitter 手动更改行高时,它会用新的固定大小替换绑定(并删除绑定)。

您是否有任何想法或解决方法如何创建可使用 GridSplitter 调整大小但仍根据 clr 属性/绑定更改其高度的两行?

I'm having a hard time with grid splitter. I've bound the RowDefinition.Height dependency property to the clr property of the model as presented below.


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

This works fine just until the GridSplitter is used. When the height of the row is changed manually with GridSplitter, it replaces the binding with the new fixed size (and removes the binding).

Have you got any ideas or workarounds how to create two rows that would be resizable with GridSplitter but still change their height according to the clr property/binding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-10-28 03:06:48

我认为问题在于您的源属性 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

通过在下部 TextBox 中输入值来设置 RowDefinition.Height,并使用 GridSplitter 调整 RowDefinition.Height 的大小代码>

I think the problem is that your source Property Height is of type double and RowDefinition.Height is of type GridLength. Use a converter and it'll work 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;
    }
}

Update
Uploaded my sample application here: http://www.mediafire.com/download.php?pgibb205d65596q

Set the RowDefinition.Height by entering a value in the lower TextBox and resize the RowDefinition.Height with the GridSplitter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文