If you already created a Windows 8 Application in HTML 5 and JavaScript maybe you already used a page control. Every page control has a Java Script file behind this, like in ASPX and WinForms. In this blog post I want to talk about some methods that we can define in this page control – especially one.
If we create a page control from Visual Studio (Add New) you will observe that 3 defaults method are automatically added:
“updateLayout” method is called when the page layout is change. A case when this method is called by the system is when the layout is changed from landscape to portrait. What we should know about this method is what happens before and after this call.
Let imagine a scenario when the landscape is active. All the content was rendered on the screen. In the moment when the user rotates the device to portrait the next steps will happen:
all the content is re-rendered once again (all the content that is displayed dynamic is scaled
“updateLayout” function is called and our custom UI is apply.
Because of this step is aware w if you really need to do some actions in this method. If you change some UI, the user will see how the UI is rendered twice (the described steps above create this behavior). There are cased when we don’t need this method. For example if we want to apply different or to hide/show different controllers we don’t need to write Java Script. We can use CSS Media Query and specify when this CSS is applying.
In this way the user will not see strange behaviors when the view state is changed. The CSS is applied before “updateLayout” method is called. In the same time, calling this method can have affected our performance because the content is rendered twice. We should try to use this method only in the cases where we absolute need it.
In conclusion, we should try to use the HTML 5 and CSS3 as much as possible. If there are thing that can be done form HTML or CSS don’t do it from Java Script because any UI change from Java Script will trigger also a render event on the UI.
If we create a page control from Visual Studio (Add New) you will observe that 3 defaults method are automatically added:
- ready
- unload
- load
- init
- processed
- render
- error
- updateLayout
“updateLayout” method is called when the page layout is change. A case when this method is called by the system is when the layout is changed from landscape to portrait. What we should know about this method is what happens before and after this call.
Let imagine a scenario when the landscape is active. All the content was rendered on the screen. In the moment when the user rotates the device to portrait the next steps will happen:
all the content is re-rendered once again (all the content that is displayed dynamic is scaled
“updateLayout” function is called and our custom UI is apply.
Because of this step is aware w if you really need to do some actions in this method. If you change some UI, the user will see how the UI is rendered twice (the described steps above create this behavior). There are cased when we don’t need this method. For example if we want to apply different or to hide/show different controllers we don’t need to write Java Script. We can use CSS Media Query and specify when this CSS is applying.
body {
background-color: white;
}
@media screen and (-ms-view-state:snapped) {
body {
background-color: black;
}
}
@media screen and (-ms-view-state:fill) {
body {
background-color: red;
}
}
In this way the user will not see strange behaviors when the view state is changed. The CSS is applied before “updateLayout” method is called. In the same time, calling this method can have affected our performance because the content is rendered twice. We should try to use this method only in the cases where we absolute need it.
In conclusion, we should try to use the HTML 5 and CSS3 as much as possible. If there are thing that can be done form HTML or CSS don’t do it from Java Script because any UI change from Java Script will trigger also a render event on the UI.
Comments
Post a Comment