【问题标题】:How to draw horizontal line in my end of list in WPF? [duplicate]如何在 WPF 列表的末尾绘制水平线? [复制]
【发布时间】:2021-09-25 20:29:47
【问题描述】:

我想要一个蓝线拉伸结束列表项,但只有几个来。

我给了

Horizo​​ntalAlignment = "拉伸"

但它不起作用。

完整列表代码在这里

 <Grid>
        <ListBox Name="MyListBoxAddData" Margin="20" BorderThickness="0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Label Content="{Binding Id}"/>
                        <Label Content="{Binding  Path=Questions,Mode=TwoWay}"/>
                        <RadioButton Content="{Binding  Path=Option1,Mode=TwoWay}" Margin="10 5"/>
                        <RadioButton Content="{Binding Path=Option2,Mode=TwoWay}" Margin="10 5"/>
                        <RadioButton Content="{Binding Path=Option3,Mode=TwoWay}" Margin="10 5"/>
                        <RadioButton Content="{Binding Path=Option4,Mode=TwoWay}" Margin="10 5"/>
                        <TextBlock Text="{Binding Answer}" />
                        <Separator HorizontalContentAlignment="Stretch"/>
                        <Rectangle HorizontalAlignment="Stretch"  Fill="Blue" Height="4" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>

O/P

我想要一个完整的行。 提前谢谢你

【问题讨论】:

  • 问题可能是 StackPanel。您可以尝试用网格围绕您的堆栈面板并将矩形移出堆栈面板。
  • 查看编辑后的答案,了解您将如何实际解决此问题。

标签: c# wpf xaml data-binding listboxitem


【解决方案1】:

将ListBox的HorizontalContentAlignment属性设置为Stretch

<ListBox Name="MyListBoxAddData" Margin="20" BorderThickness="0"
         HorizontalContentAlignment="Stretch">
    ...
</ListBox>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2015-09-14
    • 2013-11-29
    • 1970-01-01
    • 2021-09-24
    • 2019-04-18
    • 2019-10-19
    相关资源
    最近更新 更多