I have looked at many problems and solutions regarding borders not moving with elements but none of the solutions have worked for me.
Here is a screenshot:
I have a basic template for validation:
<ControlTemplate x:Key="ErrorTemplate">
<Grid Loaded="ErrorTemplateLoaded">
<Border x:Name="errorBorder" DockPanel.Dock="Top" BorderBrush="Orange" BorderThickness="1"/>
<AdornedElementPlaceholder x:Name="placeholder"/>
<Popup AllowsTransparency="True" Placement="Right"
PlacementTarget="{Binding ElementName=errorBorder}"
IsOpen="{Binding ElementName=placeholder, Path=AdornedElement.IsFocused, Mode=OneWay}">
<StackPanel Orientation="Horizontal">
<Polygon VerticalAlignment="Center" Points="0,4 4,0 4,8" Fill="#FFE4B3" Stretch="Fill" Stroke="#FFE4B3"
StrokeThickness="2" />
<Border Background="#FFE4B3" CornerRadius="4" Padding="4">
<TextBlock HorizontalAlignment="Center" Foreground="Black" FontWeight="Bold" Margin="2,0,0,0"
Text="{Binding ElementName=placeholder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent, Mode=OneWay}" />
</Border>
</StackPanel>
</Popup>
</Grid>
</ControlTemplate>
Through Styles
this gets applied to every element I need it applied to:
<Style TargetType="CheckBox" BasedOn="{StaticResource DisableWhileLoadingProjectStyle}">
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}" />
</Style>
This means it also gets applied to Checkboxes inside my TreeView which is nice and good but when I scroll within the TreeView that's where chaos ensues.
The Border does not seem to get updated after the scroll. Only after the next scroll the border is updated with the last position of the checkbox. This means that it is not synched with the current position.
I have tried finding the ScrollViewer in code-behind and used the ScrollChanged
event to updated the border position but that did not help.
My guess is that all events get the before scroll position of the element and not after scroll.
How can I solve this problem?