Copying styles from one control to another

Discussion in 'ASP .Net' started by Josh Valino, Aug 22, 2008.

  1. Josh Valino

    Josh Valino Guest

    Hi,

    I'd like to take the style properties from one control and apply them all to
    the properties of another control, where they relate. The situation is
    this:

    I have a TreeView control, and the SelectedNodeStyle has some things set.
    In addition to the TreeView, I have a few LinkButton controls. A user can
    select a node in the tree or one of the LinkButton. I'd like the
    LinkButtons to have the same look that a selected node has when it's
    selected in the tree. Right now, I'm doing this:

    ///CODE
    private void SomeLinkButton_Click(object sender, EventArgs e)
    {
    if (this.Tree.SelectedNode != null)
    {
    this.Tree.SelectedNode.Selected = false;
    this.FormTitle.Select(this.Tree.SelectedNodeStyle);
    }
    }


    //extension method in a static class
    public static void Select(this LinkButton linkButton, Style style)
    {
    linkButton.Font.Bold = true;
    linkButton.Font.Bold = style.Font.Bold;
    linkButton.BackColor = style.BackColor;
    linkButton.ForeColor = style.ForeColor;
    }
    ///END OF CODE

    I'd like it such that if anyone comes along and specifies additional
    properties to the SelectedNodeStyle, he won't have to update the extension
    method. Is there a more efficient way than what I currently have? I could
    just manually add all the property mappings in my extension method, or I
    could reflect all the properties out. I'm not excited by either solution,
    so I'm curious if anyone has any other ideas. Oh, and tragically, just
    mapping the same CssClass property won't work because of insane political
    reasons that it hurts to think about.

    Thanks
    Josh Valino, Aug 22, 2008
    #1
    1. Advertising

  2. Josh Valino

    gerry Guest

    themes ?


    "Josh Valino" <no spam please> wrote in message
    news:...
    > Hi,
    >
    > I'd like to take the style properties from one control and apply them all
    > to the properties of another control, where they relate. The situation is
    > this:
    >
    > I have a TreeView control, and the SelectedNodeStyle has some things set.
    > In addition to the TreeView, I have a few LinkButton controls. A user can
    > select a node in the tree or one of the LinkButton. I'd like the
    > LinkButtons to have the same look that a selected node has when it's
    > selected in the tree. Right now, I'm doing this:
    >
    > ///CODE
    > private void SomeLinkButton_Click(object sender, EventArgs e)
    > {
    > if (this.Tree.SelectedNode != null)
    > {
    > this.Tree.SelectedNode.Selected = false;
    > this.FormTitle.Select(this.Tree.SelectedNodeStyle);
    > }
    > }
    >
    >
    > //extension method in a static class
    > public static void Select(this LinkButton linkButton, Style style)
    > {
    > linkButton.Font.Bold = true;
    > linkButton.Font.Bold = style.Font.Bold;
    > linkButton.BackColor = style.BackColor;
    > linkButton.ForeColor = style.ForeColor;
    > }
    > ///END OF CODE
    >
    > I'd like it such that if anyone comes along and specifies additional
    > properties to the SelectedNodeStyle, he won't have to update the extension
    > method. Is there a more efficient way than what I currently have? I
    > could just manually add all the property mappings in my extension method,
    > or I could reflect all the properties out. I'm not excited by either
    > solution, so I'm curious if anyone has any other ideas. Oh, and
    > tragically, just mapping the same CssClass property won't work because of
    > insane political reasons that it hurts to think about.
    >
    > Thanks
    >
    >
    >
    gerry, Aug 22, 2008
    #2
    1. Advertising

  3. Josh Valino

    HillBilly Guest

    Dippity-do easy using a Skin after choosing to use either
    [Theme|StyleSheetTheme] as we then go to PreInit, find the control and
    change its SkinID property to whatever we want and the predeclared
    properties in the skin are bound to the control.

    We can do the same thing without using skins and themes in PreInit by
    binding the CssClass property to a control.

    "Josh Valino" <no spam please> wrote in message
    news:...
    > Hi,
    >
    > I'd like to take the style properties from one control and apply them all
    > to the properties of another control, where they relate. The situation is
    > this:
    >
    > I have a TreeView control, and the SelectedNodeStyle has some things set.
    > In addition to the TreeView, I have a few LinkButton controls. A user can
    > select a node in the tree or one of the LinkButton. I'd like the
    > LinkButtons to have the same look that a selected node has when it's
    > selected in the tree. Right now, I'm doing this:
    >
    > ///CODE
    > private void SomeLinkButton_Click(object sender, EventArgs e)
    > {
    > if (this.Tree.SelectedNode != null)
    > {
    > this.Tree.SelectedNode.Selected = false;
    > this.FormTitle.Select(this.Tree.SelectedNodeStyle);
    > }
    > }
    >
    >
    > //extension method in a static class
    > public static void Select(this LinkButton linkButton, Style style)
    > {
    > linkButton.Font.Bold = true;
    > linkButton.Font.Bold = style.Font.Bold;
    > linkButton.BackColor = style.BackColor;
    > linkButton.ForeColor = style.ForeColor;
    > }
    > ///END OF CODE
    >
    > I'd like it such that if anyone comes along and specifies additional
    > properties to the SelectedNodeStyle, he won't have to update the extension
    > method. Is there a more efficient way than what I currently have? I
    > could just manually add all the property mappings in my extension method,
    > or I could reflect all the properties out. I'm not excited by either
    > solution, so I'm curious if anyone has any other ideas. Oh, and
    > tragically, just mapping the same CssClass property won't work because of
    > insane political reasons that it hurts to think about.
    >
    > Thanks
    >
    >
    >
    HillBilly, Aug 23, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    1,396
    Kevin Spencer
    Nov 21, 2003
  2. et
    Replies:
    1
    Views:
    505
    Yunus Emre ALPÖZEN [MCSD.NET]
    Jun 29, 2005
  3. Gactimus
    Replies:
    12
    Views:
    788
    Chris \( Val \)
    Nov 18, 2004
  4. et
    Replies:
    0
    Views:
    135
  5. Praveen

    Copying a table's properties and styles

    Praveen, Aug 26, 2005, in forum: Javascript
    Replies:
    2
    Views:
    75
    Gérard Talbot
    Aug 27, 2005
Loading...

Share This Page