Trying to style a dropdown list in Silverlight 4 - I have successfully made all of the visual style changes. The part that has me stumped is I am trying to align the dropdown (pop-up) portion of the control so that the right edge of the dropdown 开发者_如何学Gois aligned with the right edge of the control. The default is the left edge is aligned with the left edge of the control.
Any thoughts/examples? Is this hard to do or am I missing something?
thanks Michael
unfortunately it's not something you can easily do by templating (unless your control is fixed size and you don't mind hardcoding Popup offsets in the template).
There's one solution which is not that complicated though:
<Popup x:Name="Popup" Loaded="Popup_Loaded">
and then in code:
private void Popup_Loaded(object sender, RoutedEventArgs e)
{
Popup myPopup = sender as Popup;
if (myPopup != null)
{
myPopup.VerticalAlignment = VerticalAlignment.Bottom;
myPopup.HorizontalAlignment = HorizontalAlignment.Right;
}
}
What you can do is use MS Expression Blend to generate the default template for a ComboBox. In the template you will find a Popup named Popup, change it's FlowDirection attribute to RightToLeft...
<Popup x:Name="Popup" FlowDirection="RightToLeft">
Note the ScrollViewer object inside the Popup will inherit the FlowDirection set so you have to explicitly set its FlowDirection to LeftToRight...
<ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1" FlowDirection="LeftToRight">
...else it will fill from RightToLeft and the scrollbar will be on the left hand side.
精彩评论