Reputation: 113
I'm creating a webview in c# code in UWP application. I have attached a LoadCompleted event to it. When this event gets trigger ActaulHeight And ActualWidth is 0. I tried to set its MinWidth and MinHeight to 500. But its is not working.
I did the same thing by creating a webview control in XAML but in that case ActualHeight and ActualWidth is 500.
Here is the code :
public WebView _webView { get; set; }
public ViewPage()
{
this.InitializeComponent();
_webView = new WebView
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Top,
Source = new Uri(@"https://www.google.com"),
MinHeight = 500,
MinWidth = 500
};
}
private void _webView_LoadCompleted(object sender, NavigationEventArgs e)
{
// Here, when I debug _webview ActualHeight and ActaulWidth is zero.
}
Upvotes: 0
Views: 172
Reputation: 2383
ActualWidth
and ActualHeight
reflect the size of the UI element in the layout. In the C# code you only created an instance of WebView
class, but didn't really place it anywhere on the page, hence these values were zero.
On the contrary, when you used XAML, not only you created an instance of WebView
class, but also embedded this UI element into the page that was displayed when you ran the app, so ActualWidth
and ActualHeight
contained actual dimensions of the UI element on that page.
Upvotes: 1