内容我有这个组合框在我的Silverlight用户控件:自动调整大小组合框下拉菜单在Silverlight
<ComboBox
AutomationProperties.AutomationId="cmbProjects"
Grid.Row="0"
Grid.Column="2"
ItemsSource="{Binding Projects}"
SelectedItem="{Binding SelectedProject, Mode=TwoWay}"
Style="{StaticResource DefaultComboBoxStyle}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<TextBlock Foreground="DarkRed" AutomationProperties.AutomationId="{Binding Number}" Width="100" Margin="0" Text="{Binding Number, Converter={StaticResource StringFormatter},ConverterParameter='\{0\}'}" />
<TextBlock AutomationProperties.AutomationId="{Binding Description}" Text="{Binding Description, Converter={StaticResource StringFormatter},ConverterParameter='\{0\} '}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
的大部分填充ComboBox中的项目的lenghth超出控制的宽度。当我下拉列表时,下拉菜单会展开,但不会完全展示到项目内容的宽度,从而导致剪裁水平滚动条的内容。对于内容在控件的原始宽度内的完全相同的组合框,不会发生这种情况。
在WPF中,我可以简单地将item容器的宽度设置为auto;在Silverlight中这会导致一个灾难性的错误。我可以设置为一个巨大的数字,但滚动仍然出现,无论宽度如何。另外,在Silverlight 2 beta 2中,有一个DropDownWidth属性,其中一个选项是“Auto”,这在RTM中是看不到的。
我可以绕过这一点小费,主要是隐藏水平滚动条和附加一串字符,以便下拉菜单完全展开以显示项目内容。很显然,这种破解并不理想。有没有人遇到类似的问题?有没有什么我失踪,迫使组合框没有滚动条充分展开?
ib。
是的,我已经这样做了,我能想到的最好的解决方案就是我在原始问题中提到的那个,但是我可以直接从ComboBox访问我需要的修复所需的ScrollViewer属性。无论如何,我会给你一票> 8P SL3 FTW! – 2009-04-16 22:29:37