I've created a DataTemplate for my objects in a ResourceDictionary
file. The template is basically an image that is loaded from the disk. Now, what happens is that I want to align the image to a specific point on my Canvas but not by its upper left point but its center point, that's why I want to apply a translate transform for X = -Width / 2
and
Y = -Height / 2
but I don't know how to apply them via the DataTemplate.
Any help will be appreciated, thanks!
you can take the advantage of using loaded event on the data template child Example:
if you are using grid as data template content
you can write the transformation code in the .cs file using sender object.
Try using databinding on Canvas' the AttachedProperties and an IValueConverter to transform the offsets to whatever you want.
For instance: