通过添加属性来自定义现有控件

发布于 2024-09-08 17:33:27 字数 277 浏览 7 评论 0原文

我正在尝试创建一个可以采用标签属性值“Rank”的自定义 AccordionItem:

<local:MyAccItem Header="" Content="" Rank="" /> 

这实际上不起作用,因为我的控件仅包含一个包含原始 Accordion 项的网格。我尝试操作模板并使用修改后的模板创建了资源文件。但是我想更改我模板化的 AccordionItem 内 Ellipse 对象的大小,以便它根据该项目的排名而变化。我真的被困住了。帮助表示赞赏。

I'm trying to create a custom AccordionItem that can take the tag property value "Rank":

<local:MyAccItem Header="" Content="" Rank="" /> 

This isn't really working because my control simply contains a grid that contains the original Accordion item. I have tried manipulating the template and have created a Resource file with a modified template. But the I want to change the size of Ellipse object inside the AccordionItem that I have templated so that it changes based on the rank of that item. I'm really getting stuck. Help appreciated.

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

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

发布评论

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

评论(2

裸钻 2024-09-15 17:33:27

您需要在 MyAccItem UserControl 的代码隐藏中创建一个依赖属性“Rank”。我假设你的排名是一个整数?如果是这样,您可以将其放在后面的代码中,构建,然后它应该在您的 XAML 中工作。

#region Rank (DependencyProperty)

    /// <summary>
    /// Rank
    /// </summary>
    public int Rank
    {
        get { return (int)GetValue(RankProperty); }
        set { SetValue(RankProperty, value); }
    }
    public static readonly DependencyProperty RankProperty =
        DependencyProperty.Register("Rank", typeof(int), typeof(MyAccItem),
        new PropertyMetadata(0, new PropertyChangedCallback(OnRankChanged)));

    private static void OnRankChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ((MyAccItem)d).OnRankChanged(e);
    }

    protected virtual void OnRankChanged(DependencyPropertyChangedEventArgs e)
    {

    }

    #endregion Rank (DependencyProperty)

You need to create a Dependency Property 'Rank' in the codebehind of your MyAccItem UserControl. I'm assuming your rank would be an int? If so, you could put this in your code behind, build, then it should work in your XAML.

#region Rank (DependencyProperty)

    /// <summary>
    /// Rank
    /// </summary>
    public int Rank
    {
        get { return (int)GetValue(RankProperty); }
        set { SetValue(RankProperty, value); }
    }
    public static readonly DependencyProperty RankProperty =
        DependencyProperty.Register("Rank", typeof(int), typeof(MyAccItem),
        new PropertyMetadata(0, new PropertyChangedCallback(OnRankChanged)));

    private static void OnRankChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ((MyAccItem)d).OnRankChanged(e);
    }

    protected virtual void OnRankChanged(DependencyPropertyChangedEventArgs e)
    {

    }

    #endregion Rank (DependencyProperty)
一曲爱恨情仇 2024-09-15 17:33:27
#region Rank 
#endregion Rank 

这些标签用于封装它们之间的代码,因此您可以展开和折叠其中的代码。

这只是为了让事情井井有条,仅此而已!

#region Rank 
#endregion Rank 

this tags are used to encapsulate the code between them, so you can expand and collapse the code within them.

it's just to keep things organized, nothing more!

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