开发者

WPF XAML ComboBox Width

I have the following xaml with all the binding r开发者_如何学JAVAemoved;

<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.

I'm kinda new to xaml so is this default behavior or what do I do to make the combobox small?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜