0

I have an UserControl that I want to be always in a square. Height change must change the Width to same value and vice versa. Height and Width I want to hide (XAML and Property Editor) and I want to create a new property "Size". I tried to hide properties by "[Browsable(false)]" but it´s visible in XAML.

Width=Height doesn't work. Change Size property also not work. In design and XAML isn't bind width and height.

quick example:

[Browsable(false)]   //visible in XAML, but not in Property Editor!!!
public new double Width 
{ 
   get { return Width; }
   set { Height = Width = value; }  //or "Size = value;" or anything else?
}

[Browsable(false)]   //visible in XAML, but not in Property Editor!!!
public new double Height 
{ 
   get { return Height; }
   set { Width = Height = value; }  //or "Size = value;" or anything else?
}

private double size;
public double Size   //doesn´t resize the UserControl!!!
{
   get { return size; }
   set { Width = Height = size = value; }
}

Must I use ActualWidth and ActualHeight properties? Must I bind Width property with Size , ActualHeight etc.? Must I use any event between these properties? How?

sentee
  • 13
  • 5

1 Answers1

4

Pretty sure that will end up in a stack overflow as you set height to width to height to width etc. You can do this in XAML with an Element binding...

<Label x:Name="label" Width="{Binding ActualHeight, ElementName=label, Mode=OneWay}">Label</Label>
kidshaw
  • 3,423
  • 2
  • 16
  • 28