使用列表框中的自定义项目进行 Zordering - Silverlight

发布于 2024-09-25 11:12:06 字数 433 浏览 5 评论 0原文

我正在制作一个自定义按钮。 屏幕截图会很有帮助。如图所示,按钮没有问题,因为徽章挂在左侧。但是,如果我希望徽章悬挂在右侧,那么列表框中的下一个项目将遮盖徽章超出其容器边界(按钮的宽度)的部分。现在我无法用 zordering 解决这个问题,对吗?因为这仅适用于其容器内的排序,在本例中为 ListBoxItem。这里有什么可以做的吗?仅供参考,我希望避免采取解决方法,例如留出足够大的边距以便为徽章提供空间。我还有另一个自定义按钮,其文本是可编辑的,并且扩展了用于获取输入文本的文本框将远远超出底层按钮。

I'm cooking up a custom button. This screenshot will be helpful. There's no problem with the button as seen in the image because the badge is hanging off to the left. But if I want the badge to hang off the right then the next item in the listbox will obscure the parts of the badge that go beyond the bounds of it's container (the width of the button). Now I can't fix this with zordering, right? Because that only applies to the ordering within its container, in this case the ListBoxItem. Is there anything that can be done here? FYI, I'm hoping to avoid a work-around such as putting in large enough margins to give the badges room. I have another custom button whose text is editable and the expansion of the TextBox used to take the inputted text will expend well wide beyond the underlying button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻了热茶 2024-10-02 11:12:06

您需要将 ZIndex 添加到包含的 ListBoxItem 本身。一种可能适用于一小部分项目的方法是创建一个新的 ListBox 类型。

public class ZOrderedListBox : ListBox
{
    private int _ZIndex = 0;

    protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
    {
        base.PrepareContainerForItemOverride(element, item);
        Canvas.SetZIndex((UIElement)element, _ZIndex--);
    }
}

上面的 ZorderedListBox 将分配一个降序的 ZIndex,以便较早的项目比后面的项目具有更高的 zindex。 警告这个简单的解决方案仅适用于 StackPanel 作为项目面板,它不适用于默认的 VirtualizingStackPanel,这需要更复杂的方法。

You need to add a ZIndex to the containing ListBoxItem itself. One approach that might work for a small set of items it so create a new ListBox type.

public class ZOrderedListBox : ListBox
{
    private int _ZIndex = 0;

    protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
    {
        base.PrepareContainerForItemOverride(element, item);
        Canvas.SetZIndex((UIElement)element, _ZIndex--);
    }
}

The ZorderedListBox above will assign a descending ZIndex so that the earlier items have a higher zindex than later ones. Caveat this simplistic solution only works with StackPanel as the Items panel, it won't work with the default VirtualizingStackPanel, what will take greater sophistication.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文