[英]WPF XAML ComboBox Width
I have the following xaml with all the binding removed; 我删除了以下xaml,删除了所有绑定;
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left" Height="20">
<ComboBox x:Name="ddlDay" Width="30"/>
If I set the width of the combobox to 200 it works but if I set it to 50 it doesn't size past the default. 如果我设置了组合框200它的工作原理的宽度,但如果我将它设置为50它没有大小过去的默认。
I'm kinda new to xaml so is this default behavior or what do I do to make the combobox small? 我对xaml有点陌生,所以这是默认行为还是该怎么做才能使组合框变小?
I'm not able to reproduce the behavior you are describing. 我无法重现您描述的行为。 I tried it with the following test:
我通过以下测试进行了尝试:
<Window x:Class="ComboWidthSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Height="20">
<ComboBox ItemsSource="{Binding}" Width="30" />
<ComboBox ItemsSource="{Binding}" Width="50" />
<ComboBox ItemsSource="{Binding}" Width="200" />
</StackPanel>
</Grid>
</Window>
using System.Linq;
namespace ComboWidthSample
{
public partial class Window1
{
public Window1()
{
InitializeComponent();
DataContext = Enumerable.Range(1, 10).Select(i => "My ComboBox Item " + i).ToList();
}
}
}
Are you doing something different than that? 你在做些别的吗? Perhaps databinding to the Width property or styling your ComboBox?
也许是将数据绑定到Width属性,还是对ComboBox进行样式设置?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.