I have a binding failure that does seem to not be a failure, since everything with the binding works like intended. I'm guessing the binding fails but immedietely after succeeds (? but shouldnt the binding failure warning get removed then?).
The binding failure occurs in one of my templates (in a style) for a custom control (ColoredImage). However it only gives a binding failure in that template when that custom control is used inside another template for a custom control (ComPortButton). When i use the ColoredImage control elsewhere, i get no binding failures.
Error reads: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Image; DataItem=null; target element is 'ImageBrush' (HashCode=42371273); target property is 'ImageSource' (type 'ImageSource')
When i modify the template from:
<Rectangle x:Name="Icon" Fill="{Binding Path=Color, RelativeSource={RelativeSource TemplatedParent}}" Height="{Binding Path=Height, RelativeSource={RelativeSource TemplatedParent}}" Width="{Binding Path=Width, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Top">
<Rectangle.OpacityMask>
<ImageBrush ImageSource="{Binding Path=Image, RelativeSource={RelativeSource TemplatedParent}}"/>
</Rectangle.OpacityMask>
to:
<Image Source="{Binding Path=Image, RelativeSource={RelativeSource TemplatedParent}}" x:Name="Icon" Height="{Binding Path=Height, RelativeSource={RelativeSource TemplatedParent}}" Width="{Binding Path=Width, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Top"/>
Then i get no binding failure, which is odd since the same bindings is used. As a reminder, using this control (coloredimage) gives no binding failures in any other place. Only when i use it from another template.
How can i fix this? The code works like intended, i'm just sick of having the "binding failure" icon glow red all the time.
Both Styles+template for ColoredImage and ComPortButton are in Generic.xaml. Does this have anything to do with it? I tried chaning the order in which i define these styles within Generic.xaml, but it had no effect.