开发者

Customizing an existing control by adding properties

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 ma开发者_开发问答nipulating 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.


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)


#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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜