开发者

Specifying Silverlight combobox popup direction (dropup)

Is it possible to make the silverlight combo-box "drop up" i.e. display the popup above the combo-box instead o开发者_如何转开发f bellow as per default?


The first step is to define your own ComboBox Template, that contains the definition of the Popup. Edit a copy using Blend for example.

However, placing that Popup above is not an easy task as Silverlight Popups have no Placementor PlacementTarget properties like in WPF that would allow to display it above.

Luckily Kent Boogaart wrote an Attached Behavior that adds this capability and it is used like this:

<Popup b:PopupPlacement.PlacementTarget="{Binding ElementName=ContentPresenterBorder}">
    <b:Popup.PreferredOrientations>
        <b:PopupOrientationCollection>
            <b:PopupOrientation Placement="Top" HorizontalAlignment="Center"/>
            <b:PopupOrientation Placement="Bottom" HorizontalAlignment="Center"/>
            <b:PopupOrientation Placement="Right" VerticalAlignment="Center"/>
            <b:PopupOrientation Placement="Right" VerticalAlignment="TopCenter"/>
        </b:PopupOrientationCollection>
    </b:Popup.PreferredOrientations>

    <!--Popup content with the ItemPresenter-->
</Popup>

Where ContentPresenterBorder is the name of the container that holds the ToggleButton of the ComboBox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜