This project is read-only.

Password protected pages

May 20, 2013 at 9:52 AM
Hi.

I’m developing an application like the wonderful demo project.
When I click onto “settings” I want to ask the password for continue. Inside my app only Admin must change the settings.
For test purpose I’ve implemented the interface IContent inside the demo class Introduction.
In the method OnNavigatingFrom I intercept the action, ask the password and so on. It works fine.

My doubt is the follow: I would avoid to implement IContent inside all pages. Is there a smart strategy to concentrate the password check in only one point?

Thanks in advance.
May 20, 2013 at 3:05 PM
Implement the IContent interface in a base class and derive your password protected pages from this class.
May 20, 2013 at 4:38 PM
Hello.

Thank you for your fast reply.
Of course: this was my first solution. Unfortunately all pages inherits from UserControl class.
And the UserControl doesn’t works easily if you subclassing it.
May 21, 2013 at 3:53 PM
What do you mean with 'doesn't work easily'?
May 21, 2013 at 4:44 PM
Edited May 21, 2013 at 4:52 PM
Because I’ve not yet found how to derive several user controls from ONE common ancestor without got problems with visual studio auto-generated method (i.e. InitializeComponent()).
If you have a good example I appreciate it a lot.

Thanks.
May 21, 2013 at 4:53 PM
Edited May 21, 2013 at 4:54 PM
Assume you have the following plain c# class (no xaml):
public class SecurePage : UserControl, IContent
{
  // IContent implementation here
}
Then you can easily derive from it by adding a new UserControl and replace the UserControl tag with SecurePage where the local xmlns prefix is registered to the clr namespace containing SecurePage. In below sample, SecurePage is located in the namespace ModernUIApp.Pages.
<local:SecurePage x:Class="MyPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ModernUIApp.Pages"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid Style="{StaticResource ContentRoot}">
        <ScrollViewer>
            <StackPanel MinWidth="200">
                <TextBlock Text="TODO: add content" />
            </StackPanel>
        </ScrollViewer>
    </Grid>
</local:SecurePage>
May 22, 2013 at 12:02 PM
It works!

Thank you so much.

Diego.