如何将一条线的长度绑定到一行的高度?

时间:2014-08-27 03:28:18

标签: wpf xaml

我添加了一行,但我不知道如何设置它的位置。(现在我只是把它放在画布上)我想要做的是绑定行长度=第一行的高度(现在自动)。

<DataTemplate DataType="{x:Type vm:SettingsViewModel}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Border Grid.Row="0" Margin="0,0,0,0" >
            <!--
            <Grid.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Offset="0" Color="White"/>
                    <GradientStop Offset="1" Color="LightGray"/>
                </LinearGradientBrush>
            </Grid.Background>-->

            <Grid>
                <Grid.ColumnDefinitions >
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="0.1*"/>
                </Grid.ColumnDefinitions>
                <TextBox Grid.Column="0" Background="AliceBlue" BorderThickness="0"></TextBox>
                <Border Background="AliceBlue" Grid.Column="1">
                    <Image Source="/Images/search.png"  ></Image>
                </Border>
                <Canvas Grid.Column="2">
                    <Line X1="0" Y1="0" X2="0" Y2="10" Stroke="Black"/>
                </Canvas>
            </Grid>

        </Border>
        <TreeView Style="{StaticResource ResourceKey=SearchableTreeView}" ItemsSource="{Binding Path=Roots, Mode=OneWay}" Background="Transparent" Grid.Row="1"/>
    </Grid>
</DataTemplate>

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您只想要一个分隔符,为什么不使用Rectangle代替Line

         <Grid>
            <Grid.ColumnDefinitions >
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="0.1*"/>
            </Grid.ColumnDefinitions>
            <TextBox Grid.Column="0" Background="AliceBlue" BorderThickness="0"></TextBox>
            <Border Background="AliceBlue" Grid.Column="1">
                <Image Source="/Images/search.png"  ></Image>
            </Border>
            <Rectangle Grid.Column="2" VerticalAlignment="Stretch" Width="1" Margin="2" Stroke="Black" />
        </Grid>