J
Josh Valino
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
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