扩大silverlight组合框控制上行?

时间:2011-07-25 19:32:11

标签: c# .net silverlight combobox

有没有办法在Silverlight中改变组合框控件的扩展方向而不是向下?

我的意思是想到youtube的视频质量组合框从下到上打开(组合框选择240p,340p等)。如果我把组合框放在布局的底部,它的开放上部默认但是有没有办法在任何其他地方实现这一目标?

1 个答案:

答案 0 :(得分:1)

您需要使用附加行为,因为ComboBox的Silverlight弹出控件没有Placement属性。可以在此处找到此类行为的示例:Silverlight Popup with Target Placement

然后,您所要做的就是应用一种样式,将行为附加到Popup:

<Style x:Key="ComboBoxStyle1" TargetType="ComboBox">
    ... snip ...
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid>
                    ... snip ...

                    <!-- Attach behaviour here! -->
                    <Popup x:Name="Popup">
                        <Border x:Name="PopupBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3" HorizontalAlignment="Stretch" Height="Auto">
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                    <GradientStop Color="#FFFEFEFE" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.Background>
                            <ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1">
                                <ItemsPresenter/>
                            </ScrollViewer>
                        </Border>
                    </Popup>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>