I am making a template using Usercontrol in WPF(C#).
However, when applying this user control, is it possible to subtract a specific part? For example, removing a button?
CodePudding user response:
To substract specific parts from UserControl, Visibility (Collapse, Hidden) option can be used. Make sure to add dependency property in UserControl for Visibility to show & hide specific part.
CodePudding user response:
It sounds like you are just trying to hide an existing button, which you should do by setting Visibility
to Visibility.Collapsed
or Visibility.Hidden
. This should be done through a binding to the ViewModel of your user control.
If you need a pure XAML solution: No it is not possible as such. However, the reverse is possible: you can add content to a user control, and that effectively provides the same functionality.
What you could do is make a base user control that doesn't contain the button, and instead has a content presenter. A second user control could wrap the base user control and define a button as its content. Then when you don't want to use the user control with the button you can simply create an instance of the base user control.