The*_*ine 7 silverlight wpf combobox
我在Silverlight中有一个ComboBox,它的行为非常不一致.
我将ComboBox绑定到动态数据集合,其中添加或删除了元素.这是ComboBox的XAML:
<ComboBox Margin="0,-1,0,0" Width="20" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemsContained}" x:Name="TabComboBox" >
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Background="White" MinWidth="250" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
所以这很好用,ComboBox用ItemsContained中的长项列表打开"up".但是,如果我删除ItemsContained中的一个项目,当你点击它时,ComboBox会突然从打开"向上"切换到打开"向下",尽管这个集合中有很多项目,它只有20个左右的像素空间可以打开.我无法弄清楚这一点.我甚至尝试将ItemsPanelTemplate设置为具有MinHeight,但这没有帮助.有谁知道如何使ComboBox始终打开"up"?
而且,即使我将MinHeight设置为荒谬的东西,例如10,000,它仍然会这样做.
编辑:作为更新,每次更改ItemsContained时,我都会通过创建一个全新的ComboBox来实现这一点.这是代码:
scrollingGrid.Children.Remove(tabComboBox);
tabComboBox.ItemsSource = null;
ComboBox boxy = new ComboBox()
{
ItemsSource = ItemsContained
};
scrollingGrid.Children.Add(boxy);
tabComboBox = boxy;
Run Code Online (Sandbox Code Playgroud)
我觉得这有点特别,所以如果有人有更好的想法,请告诉我.在ComboBox中更改ScrollViewer的高度也不起作用.
小智 2
我认为这是一个 Silverlight Bug。当您设置 ItemsSource 属性时,组合框弹出窗口的行为会从向上更改为向下。
我在每个组合框的 DropDownClosed 事件中克隆了我的组合框,这对我有用。
Private Sub cbRow1_DropDownClosed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbRow1.DropDownClosed, cbRow2.DropDownClosed, cbRow3.DropDownClosed, cbRow4.DropDownClosed, cbRow5.DropDownClosed
Dim co As ComboBox = CType(sender, ComboBox)
CloneComboBox(co)
End Sub
Private Sub CloneComboBox(ByVal co As ComboBox)
Dim cbClon = New ComboBox()
cbClon.Margin = co.Margin
cbClon.Width = co.Width
cbClon.Height = co.Height
cbClon.Name = co.Name
cbClon.Tag = co.Tag
cbClon.ItemsSource = co.ItemsSource
cbClon.SelectedIndex = co.SelectedIndex
LayoutRoot.Children.Remove(co)
LayoutRoot.Children.Add(cbClon)
//this is because I have my comboboxes inside a grid
System.Windows.Controls.Grid.SetRow(cbClon, cbClon.Tag)
System.Windows.Controls.Grid.SetColumn(cbClon, 0)
AddHandler cbClon.DropDownClosed, AddressOf cbRow1_DropDownClosed
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1623 次 |
| 最近记录: |