RelativeSource TemplatedParent does not work in Noesis.
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>
- Attachments
-
- WpfApp4.rar
- (172.02 KiB) Downloaded 116 times
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: RelativeSource TemplatedParent does not work in Noesis.
The problem is you are using a resource that is defined for the ControlTemplate, and the Binding is being resolved against the ControlTemplate, which doesn't have a TemplatedParent.
This doesn't work in WPF either because it uses the same resource for all the instances of the control, so it can't have different values for each control.
The solution is to define the ImageBrush resources in the visual tree of the template, so each instance of the control gets its own instance of the image brush:
This doesn't work in WPF either because it uses the same resource for all the instances of the control, so it can't have different values for each control.
The solution is to define the ImageBrush resources in the visual tree of the template, so each instance of the control gets its own instance of the image brush:
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 21 guests