I'm developing an UWP app with a ContentDialog which has a TextBox
. I want to enable caching for the ContentDialog
so that the state of the ContentDialog does not change even after closing the dialog.
In other words, if an user enter their name in the above mentioned TextBox
. The name should not be reset even after closing the dialog. Again after reopening the dialog, the user's name should be there in the TextBox.
Thanks in Advance.,
CodePudding user response:
How do I enable CacheMode in ContentDialog in UWP C#?
To achieve this behavior, please make sure that you are not creating a new ContentDialog
every time when you are trying to show a ContentDialog
. As long as you are always calling the same ContentDialog
instance and you are not resetting the values manually, the status of the ContentDialog
won't be changed.
For example, I created a ContentDialog
in XAML like this:
<ContentDialog x:Name="MyDialog"
Width="500"
PrimaryButtonText="OK"
SecondaryButtonText="Cancel" >
<StackPanel Height="Auto" Width="450" Orientation="Vertical">
<TextBlock x:Name="txtHotlistMsg" Text="Title"/>
<ToggleButton Content="Check" IsChecked="False"/>
<TextBox x:Name="ttBox" PlaceholderText="Type something"/>
</StackPanel>
</ContentDialog>
If I call the MyDialog.ShowAsync()
method in the code-behind, type something in the TextBox
or checked the ToggleButton
and then close the button with the OK button. The status of them won't be changed when you open the ContentDialog
again.