Tho*_*que 21 wpf combobox placement drop-down-menu
我正在尝试创建一个ComboBox
非标准的下拉对齐.基本上,我希望下拉列表位于下方ComboBox
,但与ComboBox
左边缘的右边缘对齐.
通常的ComboBox
样子,使用PlacementMode="Bottom"
:
我想要的是:
我试图Popup.PlacementMode
在我的模板中使用该属性ComboBox
,但没有一个可能的值似乎做我想要的.有没有一种简单的方法,最好是纯XAML?
vor*_*olf 41
当我打开Expression Blend时,我在几秒钟内就提出了解决方案:
<Popup Placement="Left" VerticalOffset="{TemplateBinding ActualHeight}"
HorizontalOffset="{TemplateBinding ActualWidth}"
Run Code Online (Sandbox Code Playgroud)
有时这个应用程序比手工编写xaml更有用,但不常见.
我将对PopUp使用“自定义”放置模式,并声明一个回调以将弹出控件放置在正确的位置,如此处所示:WPF ComboBox DropDown Placement
看看这里的示例是否适合您:
public class TestComboBox : ComboBox
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var popup = (Popup)Template.FindName("PART_Popup", this);
popup.Placement = PlacementMode.Custom;
popup.CustomPopupPlacementCallback += (Size popupSize, Size targetSize, Point offset) =>
new[] { new CustomPopupPlacement() { Point = new Point (targetSize.Width-popupSize.Width, targetSize.Height) } };
}
}
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助,问候
归档时间: |
|
查看次数: |
24058 次 |
最近记录: |