So the problem is that I created a custom Control which holds 3 other controls deriving from FrameworkElement:
class TextArea : Control {
private List<LocalViewBase> views;
private Views.TextView.View textView;
private Views.CaretView.View caretView;
private Views.SelectionView.View selectionView;
protected override int VisualChildrenCount => views.Count;
protected override Visual GetVisualChild(int index) => views[index];
public TextArea() {
views = new List<LocalViewBase>();
SetViews();
}
private void SetViews() {
textView = new Views.TextView.View() { Margin = new Thickness(EditorConfiguration.GetTextAreaLeftMargin(), 0, 0, 0) };
textInfo = new LocalTextInfo(textView);
selectionView = new Views.SelectionView.View(textInfo) { Margin = new Thickness(EditorConfiguration.GetTextAreaLeftMargin(), 0, 0, 0) };
caretView = new Views.CaretView.View(textInfo) { Margin = new Thickness(EditorConfiguration.GetTextAreaLeftMargin(), 0, 0, 0) };
foreach (var view in new LocalViewBase[] { selectionView, textView, caretView }) {
views.Add(view);
AddVisualChild(view);
AddLogicalChild(view);
}
}
}
public abstract class LocalViewBase : FrameworkElement { }
LocalViewBase is currently an empty class deriving from FrameworkElement.
The problem I'm dealing with right now is that only the OnRender of the earliest added child is being called - in this case selectionView - and only it is drawn with a proper margin. I tried @devhedgehog's answer from here: WPF - Visual tree not used for drawing? but it doesn't do the trick for me. Even if I extend the Panel class instead of Control and use its Children collection instead of calls to AddVisualChild() and AddLogicalChild(), still the views aren't draw with a proper margin. I also tried every method like InvalidateWhatever() but it also didn't help.
Probably the other views are not drawn with a correct margin, because all of them are stacked on top of each other and WPF "thinks" that only the selectionView is visible, so the actual question is - how do I convince it to think otherwise? :)