【发布时间】:2019-05-21 10:57:29
【问题描述】:
我正在开发一个遵循 MVVM 的 WPF 应用程序。我在应用程序中有两个组合框。一个绑定到整数列表,另一个绑定到字符串列表。问题是组合框的高度不同(见下图)。知道为什么高度不同吗?两个组合框都不涉及样式。
查看:
<UserControl.Resources>
<Style TargetType="ComboBox" >
<Setter Property="Margin" Value="5" />
</Style>
<Style TargetType="TextBlock" >
<Setter Property="Margin" Value="5" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</UserControl.Resources>
...
<StackPanel>
<TextBlock Text="{x:Static p:Resources.OutputLayersAsText}" />
<ComboBox ItemsSource="{Binding StringCollection}" />
<TextBlock Text="{x:Static p:Resources.IgzStatAreaSizeText}" />
<ComboBox ItemsSource="{Binding IntegerCollection}" />
</StackPanel>
视图模型:
private ObservableCollection<string> _stringCollection;
public ObservableCollection<string> Stringcollection => _stringCollection ?? (_stringCollection = new ObservableCollection<string>
{
".igz", ".png+.png", ".jpg+.png"
});
private ObservableCollection<int> _integerCollection;
public ObservableCollection<int> IntegerCollection => _integerCollection ?? (_integerCollection = new ObservableCollection<int>
{
8, 12, 16, 24, 32, 48, 64, 96, 128
});
我还尝试了另一个带有枚举集合的组合框,它的高度与整数组合框高度相似。
【问题讨论】:
-
你在这里只展示了故事的一半......那个 UI 的其余部分在哪里?
-
@NawedNabiZada 这些是我在 UI 中仅有的控件。
-
图片表示别的东西
-
@NawedNabiZada 添加了全图。
-
您是否重新设计了您的 ComboBox ?如果没有,那么仍然缺少一些东西。