我有一个 ContentControl 从左到右由一个 Button、一个分区和一个 ComboBox 组成。我希望 ComboBox 下拉列表与控件的左侧对齐,而不是与组合框的左侧对齐。似乎找不到关于相对位置等的文档。有人处理过这个吗?TIA
问问题
5278 次
1 回答
4
我之前做过类似的事情 - 我最终从 ComboBox 派生,获取控件的弹出部分并使用CustomPopupPlacementCallback来定位它。像这样的东西...
class MyComboBox : ComboBox
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var popup = (Popup)Template.FindName("PART_Popup", this);
popup.Placement = PlacementMode.Custom;
popup.CustomPopupPlacementCallback = placePopup;
}
private CustomPopupPlacement[] placePopup(Size popupSize, Size targetSize, Point offset)
{
var placements = new[] { new CustomPopupPlacement() };
placements[0].Point = // position the drop-down here!
return placements;
}
}
于 2009-12-01T12:50:10.130 回答