I liked this answer, and it almost fit me.
But, how can I achieve this if my DataTemplate
is in a external ResourceDictionary
The DataContext
in the UserControl
is your model object, so you can directly bind to its properties like this:
Text="{Binding SomeProperty}"
(If only a path is specified the binding is relative to the DataContext
, note that in the answer you linked the intention was to have a TwoWay
binding on the DataContext
itself which was a primitive string, this cannot be done using a simple binding like {Binding .}
, a property path targeting an actual property needs to be specified)
Since the DataContext
behind OperationView
will be an object of type Operation
, then you simply bind to whatever property on Operation
you want
<!-- DataContext will be model:Operation per your DataTemplate -->
<UserControl x:Class="TryERP2.Cadastro.View.OperationView"
... some hidden NS ... >
<StackPanel>
<Label Content="Id" />
<TextBox Text="{Binding Id}" />
<Label Content="Description" />
<TextBox Text="{Binding Description}" />
</StackPanel>
</UserControl>