0

I'm probably missing something fundamental, but don't know what.

I'm in the process of converting a Tempalate10 UWP app to Windows Template Studio.

I've got most of my code moved over to the new project, but what strikes me is that when a page is loaded (navigated to), not everything seems to load the first time. I try the second time and it loads everything. What am I missing?

Added code:

<StackPanel Visibility="{x:Bind ViewModel.ItemFinalized, Mode=OneWay}">
                            <TextBlock TextWrapping="WrapWholeWords">This text</TextBlock>
                            <ToggleSwitch x:Name="toggleSwitchSaveCopies2"
                                      Margin="0,0,0,0"
                                      IsOn="{x:Bind ViewModel.SavePdfCopies, Mode=TwoWay}"
                                      Visibility="{x:Bind ViewModel.HasLineItems, Mode=OneWay}"
                                      OffContent="Don't save PDF copies."
                                      OnContent="Save and show me the PDFs."></ToggleSwitch>
                            <ToggleSwitch x:Name="toggleSwitchComposeEmail2"
                                      Margin="0,0,0,0"
                                      IsOn="{x:Bind ViewModel.ComposeEmail, Mode=TwoWay}"
                                      OffContent="Don't compose an email."
                                      OnContent="Compose an email."></ToggleSwitch>
                            <Button x:Name="buttonSaveFinalized"
                                IsEnabled="{x:Bind ViewModel.CanSave, Mode=OneWay}"
                                Content="Save"
                                Margin="0,12,0,20"
                                Click="ButtonSaveFinalized_Click" />
                            <Button x:Name="buttonViewScanSheetPDF"
                                Content="Test"
                                Margin="0,25,0,20"
                                Click="ButtonViewScanSheetPDF_Click" />
                        </StackPanel>

ViewModel:

public bool ItemFinalized { get => itemFinalized; set { Set(ref itemFinalized, value); RaisePropertyChanged("IsDraft"); } }
Carlo Mendoza
  • 765
  • 6
  • 24
  • Could you share more code? what was not load at the first time? – Nico Zhu Feb 20 '19 at 03:17
  • Not sure I can show succinct code. Although, I seem to be in a better place with this by setting all `Mode=OneTime` to `Mode=OneWay` on `x:Bind` and `Binding` in the XAML code. It's not addressing the problem 100%. I still have parts of that page not behaving as it does in the Template10 version. Looking at `RaisePropertyChanged` lines in my ViewModel now. – Carlo Mendoza Feb 20 '19 at 06:20
  • Is there a way to "preload" a page or all pages? – Carlo Mendoza Feb 20 '19 at 06:32
  • If the data source of of the page is too big, you could use asynchronous loading. – Nico Zhu Feb 20 '19 at 06:39
  • I added some code to show above. I wouldn't consider these big since they're just `bool` values to set `Visibility` and state of XAML controls. It seems to be an issue for controls towards the end of the page, but not sure if it's coincidence. The behavior of the code above is although `ItemFinalized` is `true`, the `StackPanel` is not visible. – Carlo Mendoza Feb 20 '19 at 07:04
  • Could your set break point on `itemFinalized` get method, then check if it has value when first load. – Nico Zhu Feb 20 '19 at 09:38
  • @NicoZhu-MSFT It's `true` throughout. Same value throughout. – Carlo Mendoza Feb 20 '19 at 18:08

1 Answers1

0

To summarize what eventually worked:

Mode=OneWay on x:Bind and Binding

Adding more RaisePropertyChanged in certain Properties bound to XAML control Visibility

Carlo Mendoza
  • 765
  • 6
  • 24