C# 如何增加单选按钮之间的间距
我找不到任何方法来增加每个单选按钮之间的间距以匹配我的界面格式 这是我单选按钮的XAML代码C# 如何增加单选按钮之间的间距,c#,.net,wpf,xaml,devexpress,C#,.net,Wpf,Xaml,Devexpress,我找不到任何方法来增加每个单选按钮之间的间距以匹配我的界面格式 这是我单选按钮的XAML代码 <dxe:ListBoxEdit Name="xrbSplitFreight" Grid.Row="1" Grid.RowSpan="5" FontWeight="Bold" Grid.Column="8" Height="143" VerticalAlignment="center" Width="218" HorizontalAlignment="Left" Grid.ColumnSp
<dxe:ListBoxEdit Name="xrbSplitFreight" Grid.Row="1" Grid.RowSpan="5" FontWeight="Bold" Grid.Column="8" Height="143" VerticalAlignment="center" Width="218" HorizontalAlignment="Left" Grid.ColumnSpan="3" ShowBorder="False" Margin="0,0,0,7">
<dxe:ListBoxEdit.StyleSettings>
<dxe:RadioListBoxEditStyleSettings />
</dxe:ListBoxEdit.StyleSettings>
这就是我填充按钮的方式
private void InitSources()
{
List<String> source = new List<String>();
source.Add("Split Freight");
source.Add("Print Comment");
source.Add("Do Not Split Freight");
xrbSplitFreight.ItemsSource = source;
}
private void InitSources()
{
列表源=新列表();
来源。添加(“拆分运费”);
来源。添加(“打印评论”);
来源。添加(“不拆分运费”);
xrbSplitFreight.ItemsSource=来源;
}
我尝试了许多属性,如填充和边距属性,但它不会改变间距。尝试使用
边距
在控件之间添加空格
<RadioButton Margin="5"></RadioButton>
或
编辑
看看这个
<ListBox ItemsSource="MyList">
<ListBox.ItemTemplate>
<DataTemplate>
<RadioButton Margin="10" Content="{Binding Value}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
每个
单选按钮
都用给定的边距隔开。我认为问题在于您试图将单选按钮放在列表框内。您是否尝试过将它们放入具有垂直方向属性的StackPanel中?如果您愿意尝试,您可能能够在它们之间设置边距。如果我理解正确,您想要的是增加每个radiobox与其文本之间的间距,使其与复选框与其上方文本之间的间距相匹配
这里的问题是radiobox内容没有边距属性,无法独立于radiobox移动内容。幸运的是,在WPF中,您可以将几乎所有控件封装在任何其他控件中。因此,解决方案不是使用简单文本,而是使用一个可以显示文本并具有如下边距属性的控件:
<RadioButton GroupName="GroupName">
<RadioButton.Content>
<TextBlock Text="Option 1" Margin="5 0 0 0"/>
</RadioButton.Content>
</RadioButton>
dxe:RadioListBoxEditStyleSettings来自哪里?什么是dxe:ListBoxEdit
?这似乎是一个非标准的列表框控件(看起来像DevExpress)。使用标准列表框,您可以使用所需的间距定义自己的项目模板。是的,我目前正在使用DevXPress,但我还没有找到一种方法来设置我想要的样式。这样做将无法处理动态数量的项目。在这里使用一个列表框是非常有意义的,imho。我试过了,它一点也没有改变。你在哪里添加了边距。您能用空白显示代码吗?编辑答案以显示单选按钮的正常列表框
。
<RadioButton GroupName="GroupName">
<RadioButton.Content>
<TextBlock Text="Option 1" Margin="5 0 0 0"/>
</RadioButton.Content>
</RadioButton>