I have below custom page renderer for UWP app, while the app always shows an empty screen, from the debug with the Loaded event, I can see the border element in the ContainerElement with ActualWidth=0 and ActualHeight = 0, I think this is why it's empty. How can I get the element on the page rendered correctly?
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
this.Loaded += JobsPageRenderer_Loaded;
var container = this.ContainerElement as Windows.UI.Xaml.Controls.Panel;
Windows.UI.Xaml.Controls.Border border = new Windows.UI.Xaml.Controls.Border { Height = 200, Width = 200, Background = new Windows.UI.Xaml.Media.SolidColorBrush(Colors.Red) };
container.Children.Add(border);
}
private void JobsPageRenderer_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var container = this.ContainerElement as Windows.UI.Xaml.Controls.Panel;
Windows.UI.Xaml.Controls.Border border = (Windows.UI.Xaml.Controls.Border)container.Children.First();
border.UpdateLayout();//doesn't help
container.UpdateLayout();//doesn't help
//border's ActualHeight and ActualWidth are always 0
}