<Canvas.DataContext>
<ViewModels:VMSomeControl Model="{Binding RelativeSource={RelativeSource TemplatedParent}}" />
</Canvas.DataContext>
<!-- DataContext is not passed into these Instances.
they also have no knowledge of their TemplatedParent. -->
<Canvas.Resources>
<!-- is there a way to use a binding that points to the datacontext within the resources ? -->
<Converters:SomeConverter x:Key="someConverter"
SomeProperty="{Binding Path=Model.SomeProperty}" />
<!-- is there a way to point Directly to the TemplatedParent ? -->
<Converters:SomeConverter x:Key="someConverter"
SomeProperty="{TemplateBinding SomeProperty}" />
</Canvas.Resources>
<SomeFrameworkElement SomeProperty="{Binding Path=Model.SomeOtherProperty, Converter={StaticResource someConverter}, ConverterParameter=0}" />
<SomeFrameworkElement SomeProperty="{Binding Path=Model.SomeOtherProperty, Converter={StaticResource someConverter}, ConverterParameter=1}" />
</Canvas>
is it possible to use bindings that use either the dataContext or the TemplatedParent Within a ControlTemplate's Root Visuals resourecs ?
Every FrameworkElement can be associated with a DataContext which will be used as the default data source during binding, if no other data source is specified in the binding code. Also, the children of this FrameworkElement auotmatically inherit this setting.
The DataContext is the source of all entities mapped over a database connection. It tracks changes that you made to all retrieved entities and maintains an "identity cache" that guarantees that entities retrieved more than one time are represented by using the same object instance.
A binding source is usually a property on an object so you need to provide both the data source object and the data source property in your binding XAML. In the above example the ElementName attribute signifies that you want data from another element on the page and the Path signifies the appropriate property.
Data binding is a mechanism in XAML applications that provides a simple and easy way for Windows Runtime Apps using partial classes to display and interact with data. The management of data is entirely separated from the way the data is displayed in this mechanism.
Previous answer is reeeeally really close. but the binding inside the multibinding should be :
<SomeFrameworkElement>
<SomeFrameworkElement.SomeProperty>
<MultiBinding Converter="{StaticResource someConverter}" >
<Binding />
</MultiBinding>
</SomeFrameworkElement.SomeProperty>
</SomeFrameworkElement>
that worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With