xaml - 一个控件向左对齐,另一个向右对齐,但占用屏幕的所有宽度

xaml - allign one control to left, another to right, but take all width of the screen

我有这样的东西:

<ListBox.ItemTemplate>
        <DataTemplate>
                <StackPanel 
                    Orientation="Horizontal"
                    Margin="2">
                    <Image Width="64" Height="64" Source="{Binding someIcon}"></Image>
                    <StackPanel Orientation="Vertical" Margin="15,1,0,1">
                        <TextBlock Text="{Binding someText}" FontSize="30" />
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Some Text"/>
                            <TextBlock Text="{Binding someText2}"/>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
                <CheckBox 
                    Content=""
                    Tag="{Binding someName}"
                    IsChecked="{Binding checked}"
                    Checked="someChecked"
                    Unchecked="someUnchecked"/>
         </DataTemplate>
</ListBox.ItemTemplate>

在列表框中。

我需要将 StackPanel 对齐到左侧,将 CheckBox 对齐到右侧。我需要采用所有可能的屏幕宽度并将 CheckBox 放置在屏幕的右边缘。屏幕宽度可以更改,因为它是通用 Windows 应用程序。

我该怎么做?

我试过使用 RelativePanel 和 Grid,但没有成功。当我将 Grid 与 3 列一起使用时:

<Grid.ColumnDefinitions>
 <ColumnDefinition Width="Auto" />
 <ColumnDefinition Width="*" />
 <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

我在 StackPanel 之后得到 CheckBox,而不是在屏幕的末尾。

然而,当我使用 RelativePanel 时,我使用 CheckBox 代替 StackPanel,即使我在 CheckBox 中使用 RelativePanel.AlignRightWithPanel="True",在 StackPanel 中使用 RelativePanel.AlignLeftWithPanel="True",在 RelativePanel 中使用 HorizontalAlignment="Stretch"

你有什么想法吗?

试试这个

当您 HorizontalContentAlignment 拉伸项目时,将占用整个 ListBox 宽度

           <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                </Style>
            </ListView.ItemContainerStyle>
....
        </ListBox>