将文本框与listview WPF对齐

时间:2018-07-26 23:40:31

标签: wpf listview

enter image description here

XAML:

<ListView x:Name="CoinsBox" Margin="10,28,0,76"  Width="336"  >

    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Height="40"  >
                    <TextBlock Text="{Binding Title}"   VerticalAlignment="Top"  HorizontalAlignment="Left"   />
                    <TextBlock Text="{Binding TitleShort}"  VerticalAlignment="Bottom"   HorizontalAlignment="Left"  />
                    <TextBlock Text="{Binding Price}"    VerticalAlignment="Top"   HorizontalAlignment="Right" />
                    <TextBlock Text="{Binding Volume}"   VerticalAlignment="Bottom"  HorizontalAlignment="Right" />
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

如何将两个文本框相互放置?

如果Orientation="Vertical"

enter image description here

最后两列应该在下

现在

enter image description here

它必须是

enter image description here

1 个答案:

答案 0 :(得分:1)

像这样使用嵌套堆栈面板。然后,要控制列之间的间距,请在内部堆栈面板之一中放置边距。

<StackPanel Orientation="Horizontal">
    <StackPanel Orientation="Vertical">
        <TextBlock Text="Haxen"/>
        <TextBlock Text="hxn"/>
    </StackPanel>
    <StackPanel Orientation="Vertical">
        <TextBlock Text="10000$"/>
        <TextBlock Text="40404040"/>
    </StackPanel>
</StackPanel>