RelativeSource TemplatedParent does not work in Noesis.
Posted: 20 Jul 2020, 17:49
Hello! I'm writing a nine slice control, and I'm having trouble binding my imagebrushes to my template. ImageSource is a custom dependency property. This binds correctly in WPF but not Noesis (it just shows the ImageBrush's ImageSources as null):
Oddly enough, using a simple TemplateBinding didn't work in WPF or Noesis. Is there a reason why you can't use TemplateBinding here? Naming my ControlTemplate and using ElementName also didn't work. As a workaround I manually set the ImageSources in my custom control. I attached the WPF project that has this working.
Code: Select all
<Grid.Resources>
<Style TargetType="Rectangle">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="RenderOptions.BitmapScalingMode" Value="NearestNeighbor" />
</Style>
<ImageBrush
x:Key="TLeft"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
<ImageBrush
x:Key="T"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
<ImageBrush
x:Key="TRight"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
<ImageBrush
x:Key="CLeft"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
<ImageBrush
x:Key="C"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
<ImageBrush
x:Key="CRight"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
<ImageBrush
x:Key="BLeft"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
<ImageBrush
x:Key="B"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
<ImageBrush
x:Key="BRight"
ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}"
ViewboxUnits="Absolute" />
</Grid.Resources>