-2

I have a view that is a UserControl, that has a DataContext, and all the controls bind to it. Now, I want to set a property on the view itself, to control visibility of some things, and I don't want to put the props in the ViewModel, where they shouldn't be. I tried with relative binding, with FindAncestor and TemplatedParent, but I can't make it work.

Thanks.

mZm
  • 136
  • 7
  • 1
    TemplatedParent only works in a ControlTemplate. Use `RelativeSource={RelativeSource AncestorType=UserControl}`. – Clemens Aug 20 '23 at 09:56
  • That makes a lot of sense, though I still can't seem to get it to work... Do I need to use dependency props, or could I just use regular prop, since I am setting it in xaml directly, not binding to something else? – mZm Aug 20 '23 at 16:46
  • It's unclear what exactly your problem is, you haven't provided any source code. A question like "*Do I need to use dependency prop(ertie)s*" could easily be answered by yourself by trying it out. In general, any custom property of a DependencyObject would typically be declared as dependency property. – Clemens Aug 20 '23 at 18:04
  • Well, I've already tried both, to no avail... The situation is quite simple, but there is so much code that is already there, I guess I could make a dummy example... When I make it, I will post it here... Thanks – mZm Aug 20 '23 at 21:49

0 Answers0