Category: Win10UWP

make x:Bind memory clean in UWP

Some tips here:
1. If memory has PropertyChangedHandler left, make sure the list does not have any item.
2. Call Page.Bindings.StopTracking() in Page_Unloaded event
3. If you use x:Bind with MvvmLight, and using RelayCommand, you need to set RelayCommand enity to null in Page_Unloaded.
4. For checking the page is completely released, use the launch mouse recorder to open page and back multiple times. It is important to ensure every PageBack&GC cleared all no used memories.

=============Important Update=============
Don't use Bindings.StopTracking()! When switch pages quickly, some xaml components would not be released!
Use

SimpleIoc.Default.Unregister<ViewModel>(key); 

Instead

Attached Property in StateTriggers

The demo code like the follow below:

            <VisualState x:Name="view720">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="720" />
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="Text.(Grid.ColumnSpan)" Value="3" />
                    <Setter Target="Text.(RelativePanel.Below)" Value="Image" />
                </VisualState.Setters>
            </VisualState>

So just add the parentheses around the attached property and it would be worked fine on StateTriggers.