Reputation: 5885
I got a FrameworkElement
within the eventhandler of a class. Is there a possibility to check if this FrameworkElement
is an element that has a borderthickness/borderbrush property ?
Like
var element = myframeworkelement as IHasBorder;
element.borderthickness = new Thickness(1,2,3,4);
Does something like this exist ?
Upvotes: 2
Views: 831
Reputation: 8907
The properties BorderThickness
and BorderBrush
are defined in the Control
class.
So you can try to cast your FrameworkElement
to Control
, and if that works, set the properties:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
var pnl = new StackPanel();
this.Content = pnl;
var button = new Button();
button.Content = "Hi";
pnl.Children.Add(button);
SetBorder(button);
}
public void SetBorder(FrameworkElement fe)
{
var borderControl = fe as Control;
if (borderControl != null)
{
borderControl.BorderThickness = new Thickness(10);
borderControl.BorderBrush = Brushes.Red;
}
}
}
Upvotes: 3