简体   繁体   中英

Windows Store Apps: ScrollViewer delay in data binding?

I have a LayoutAwarePage where its layout is a ScrollViewer that wraps some controls (Text boxes, text blocks, ...), these controls are bound to properties in the view model.

My problem is that when I load some save values in the LoadState event of the page (saved text box values and so on), the values are retrieved correctly but not displayed in the controls, something like this

    protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
    {
    if(pageState!=null)
    {
    if(pageState.ContainsKey(STATE_TEXT))
    {
//set the text of the text box
    txtUserName.Text=pageState[STATE_TEXT].ToString();
    }
    }
    }

When I do the above, the text box text is blank.

However, I found that when I remove the scrollviewer, it works just fine.

Also if I set the text if the txtUserName to any value in the Loaded event of the scrollviewer, the text appears normally in the text box.

what can be wrong here ?

if you use a DataContext to assign properties, maybe that's what's overriding the changes you make in the LoadState-Method.

Maybe you could share the relevant XAML, the whole (relevant) parts of the LoadState and the parts of your ViewModel that are relevant for this (ctor eg)

greetings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM