views:

181

answers:

1

 <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 ?

+1  A: 
Jakob Christensen
unfortunately you cannot use a binding on "ConverterParameter"that would be REALLY handy though.
loafofbread
You are of course absolutely right. But I think you may be able to use mulitbinding for this. I updated my answer accordingly.
Jakob Christensen
i have not yet had a chance to test this as i have been working on some other projects. but i will be sure to give you credit if it solves my issue.
loafofbread