c# - 如何在 WPF 中右对齐 RadioButton

标签 c# .net wpf xaml layout

尝试本教程 http://www.wpftutorial.net/ListBoxDataTemplate.html

并考虑添加一个单选按钮,如下所示

   <ListBox Margin="10" ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="60"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="20"/>
                    </Grid.ColumnDefinitions>
                    <Border Grid.Column="0" Margin="5" BorderBrush="Black" BorderThickness="1">
                        <Image Source="{Binding Path=Image}" Stretch="Fill" Width="50" Height="50" />
                    </Border>
                    <StackPanel Grid.Column="1" Margin="5" >
                        <StackPanel Orientation="Horizontal" TextBlock.FontWeight="Bold" >
                            <TextBlock Text="{Binding Path=Some1}" />
                            <TextBlock Text="{Binding Path=Firstname, FallbackValue=FirstName}" />
                            <TextBlock Text="{Binding Path=Lastname, FallbackValue=LastName}" Padding="3,0,0,0"/>
                        </StackPanel>
                        <TextBlock Text="{Binding Path=Age, FallbackValue=Age}" />
                        <TextBlock Text="{Binding Path=Role, FallbackValue=Role}" />
                    </StackPanel>

                    <RadioButton Grid.Column="2" Margin="5" HorizontalAlignment="Right" GroupName="A1"/>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

但结果输出是

enter image description here

将单选按钮与列表框边缘右侧对齐有什么帮助吗?谢谢

最佳答案

首先你需要get the template content to stretch ,然后您可以创建一个内容在右侧对齐的内容。

关于c# - 如何在 WPF 中右对齐 RadioButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9756651/

相关文章:

c# - 等待MDI子进程关闭,类似于ShowDialog()

.net - 为什么一个类有多个命名空间?

c# - 如何在 WPF 中将 UIElement 添加到 Grid

wpf - 在属性更改之前,您可以定义一个要播放的 Storyboard吗?

wpf - 如何将 WPF 滚动条样式应用于特定的 ListView ?

c# - OpenXml 或 Microsft.Office.Interop.Excel 在 c# 中读取 excel 文件哪个更好?

c# - Linq - 子对象上的where子句

c# - Format Decimal 2 Places - 无尾随零

c# - MVC4 View 未绑定(bind)到 POST Controller 中的模型

c# - Windows Installer 安装进度状态消息