我有两个组合框在SL页。当组合1更新、服务和填充的组合2.

在第一个电话,3返回的结果。当组合框扩大了,你可以看到所有3个选项。

在第二次呼叫,4返回的结果。当组合框扩大了,你可以看到3个选项中,有一个垂直滚吧。

如果我重做那些步骤相反,我得到4行的第一次调和3行+空白的行在第二次呼叫。(不,空白是不是一个记录。它无法选择。)

它的出现,下列大小保留的第一个产生的高度。

我怎么可以刷新组合框最大的项目显示后,每个服务电话吗?

谢谢!

编辑#1

代码下的M-V-VM模式。当网页载荷, Group1 填充的第一个组合框中,并没有什么选择。当用户使一个选择,即选择是开Group1Selection.

<ComboBox ItemsSource="{Binding Path=Group1}" SelectedItem="{Binding Path=Group1Selection}" />
<ComboBox ItemsSource="{Binding Path=Group2}" SelectedItem="{Binding Path=Group2Selection}" />

在本模型,在该组访问的 Group1Selection 酒店,我已经喜欢的东西

set
{
    if (group1Selection != value)
    {
        group1Selection = value;
        PopulateGroup2();
        OnPropertyChanged("Group1Selection");
    }
}

在PopulateGroup2执行我叫异,获取的数据,并把这些数据成为暴露的财产 Group2.

根据"正常"条件下,这不是一个问题,因为大多数的选择有几十个可能的选择。然而,一对夫妇的 Group1 选择只有3个或4个孩子的选择。如果这些选第一,然后高度的组合框,对于其余的,应用实例是设定为3或4,分别代替杏出在8所示的项目。

以下的M-V-VM的模式,没有代码代码-在后面。

有帮助吗?

解决方案

这是一个已知中的错误组合框在Silverlight2.我认为它被固定在SL3.

你可以解决这个问题通过以下:

  1. 继承该组合框

    公共类MyComboBox:组合框

  2. 得到引用的"弹"的一部分组合框内OnApplyTemplate()方法

        Popup thePopup = GetTemplateChild("Popup") as Popup;
        FrameworkElement thePopupContent = thePopup.Child as FrameworkElement;
    
  3. 复盖OnItemsChanged方法

  4. 内部复盖OnItemsChagned方法重置的高度和宽度的依赖性上的弹出窗口使用ClearValue(DP)的方法。

            thePopupContent.ClearValue(FrameworkElement.WidthProperty);
            thePopupContent.ClearValue(FrameworkElement.HeightProperty);
    

你可以清除的最大和最小高度和宽度性质如果你是担心那些了。

其他提示

这是一个理想的解决方案。谢谢markti。

对于那些有兴趣的类是这样的:

using System.Windows.Controls.Primitives; 

public class WorkAroundComboBox: ComboBox
{
    FrameworkElement thePopupContent;

    public override void OnApplyTemplate()
    {
        Popup thePopup = GetTemplateChild("Popup") as Popup;
        thePopupContent = thePopup.Child as FrameworkElement;
        base.OnApplyTemplate();
    }

    protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        thePopupContent.ClearValue(FrameworkElement.WidthProperty);
        thePopupContent.ClearValue(FrameworkElement.HeightProperty);
        base.OnItemsChanged(e);
    }
}

}

我觉得问题是,Silverlight不充分认识到背后的ComboBox 2中的数据发生了变化。也许尝试加入OnPropertyChanged("Group2")到设定为Group1 - 这应该帮助Silverlight来实现,它需要更新绑定组合框2

这也可能有助于呼吁OnPropertyChanged Group2Selection,因为以前的值不再有效。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top