0

Title says it all. In a custom control I have a button that needs to have a margin of 3, which visual studio assumes to mean "have default margin" noticeable by taking away the bold font of the property. So when I include the control inside another control where the default margin is 0, the button defaults to having 0 margin. I need it to be hard set to 3

This shows the margin property in bold, meaning it's been changed from the default value: Showing default value changed to 0

This shows the margin property set to 3 and no longer in bold (visual studio saying that the value is inherited from parent). But I don't want it to be inherited! It need to be actually set to 3! enter image description here

Here is the parent control where margin is set to be a default of 0 enter image description here

It looks fine in the designer because the form is being edited by itself without a parent form. But when testing the program, the margin of 3 is set back to 0, because that's the default margin of the parent control.

Moffen
  • 1,817
  • 1
  • 14
  • 34
  • Maybe we need a layout to see, but can you start with a screenshot demonstrating the issue? – Sinatr Jul 30 '18 at 14:47
  • Hi @Sinatr thankyou for replying. I have attached screenshots – Moffen Jul 30 '18 at 14:52
  • You're probably looking for the [`AmbientValue` attribute](https://stackoverflow.com/a/37440877/4934172). – 41686d6564 stands w. Palestine Jul 30 '18 at 14:57
  • So how do I stop margin being ambient? – Moffen Jul 30 '18 at 15:01
  • Can you show `Button_Big_1` class code? Don't forget autogenerated code too. Ideally [mcve](https://stackoverflow.com/help/mcve). I suspect default value is being not set or [attributes](https://stackoverflow.com/a/32759042/1997232). Or you didn't [inherit the property](https://stackoverflow.com/q/163611/1997232) at all? – Sinatr Jul 30 '18 at 15:20
  • I have attached a screenshot setting margin. The problem has nothing to do with button_big_1 code - I just want an instance of it to have a different margin than the others without having to code for it manually. It is possible, and works when I set the margin to be 2 or 4 or 10 etc., but when I set the margin to be 3 - Visual studio editor assumes I'm setting it to be the default value and so it defaults to 0 – Moffen Jul 30 '18 at 15:30
  • You can fix this by switching to xaml ;) hehe – Michael Puckett II Jul 30 '18 at 16:38

0 Answers0