Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Silverlight中将ComboBox下拉菜单自动调整为内容_C#_.net_Silverlight_Xaml_Silverlight 2.0 - Fatal编程技术网

C# 在Silverlight中将ComboBox下拉菜单自动调整为内容

C# 在Silverlight中将ComboBox下拉菜单自动调整为内容,c#,.net,silverlight,xaml,silverlight-2.0,C#,.net,Silverlight,Xaml,Silverlight 2.0,我的Silverlight用户控件中有一个组合框: <ComboBox AutomationProperties.AutomationId="cmbProjects" Grid.Row="0" Grid.Column="2" ItemsSource="{Binding Projects}" SelectedItem="{Binding Select

我的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>

填充组合框的大多数项的长度超过控件的宽度。当我下拉列表时,下拉列表会扩展,但不会完全扩展到项目内容的宽度,导致内容被剪切成水平滚动条。如果内容在控件的原始宽度内,则完全相同的组合框不会出现这种情况

在WPF中,我可以简单地将项目容器的宽度设置为自动;在Silverlight中,这将导致灾难性错误。我可以将with设置为一个很大的数字,但无论宽度如何,滚动条仍然会出现。另外,在Silverlight2Beta2中有一个属性DropDownWidth,其中一个选项是“Auto”,这在RTM中是看不到的

我可以通过一些技巧来解决这个问题,主要是隐藏水平滚动条并附加一些字符,以便下拉列表完全展开以显示项目内容。显然,这种黑客行为并不理想。有没有人遇到过类似的问题?在没有滚动条的情况下,强制组合框完全展开是否缺少一些内容


ib.

看来他们在SL3中修复了它

如果要调整弹出窗口,可以在组合框的控件模板中进行调整。在“混合”中,请执行以下步骤:

  • 右键单击组合框
  • 选择“编辑控制部件(模板)”
  • 选择“编辑副本”
  • 这将复制开箱即用控件样式和模板,以便您可以调整组合框弹出窗口中的ScrollViewer,使其符合您的心意


    你可能想试试我描述的解决方案。它详细说明了如何确保在添加或删除项目时更新combobox弹出窗口的高度和宽度。

    您可以使用combobox控件的MaxDropDownHeight属性。

    是的,我已经这样做了,我能想到的最佳修复方法是我在原始问题中提到的,但是我可以直接从组合框访问修复所需的ScrollViewer属性。无论如何,我会给你投票>8便士SL3 FTW!查看我的新编辑。我贴了一个链接到另一个主题,我认为可能对你有所帮助。