How to set Identity & Principle object type in WPF and WinForms

In ASP.Net, when you use MasterPages, you can provide the page with a preprocessing "MasterPage Type" command in the following lines:

<%@ MasterType VirtualPath="~/MasterPage.master" %>

      

This is used to give you access to methods and properties that are defined in the Master code string. By default when used:

Page.MasterPage

      

it returns the base MasterPage class. If you have MasterType set , it returns it as the type of your given master page [as opposed to doing something like: ctype (Page.MasterPage, MyMasterPage)]

My question is, how can I do something like this for Identity and Principle objects in my WPF application.

Basically, I have custom Identity and Principle objects (which collect a few extra fields of data) and I don't want them to explicitly display them from the public interface every time I want to access these extra fields.

0


source to share


1 answer


If you want this to be accessible from your XAML, you can inherit from the WPF class and add two properties for principal and identifier. These properties can be of type your custom Principal and Identity. Then just inherit this class for all your WPF windows.

public class AppWindow : Window
{
    public MyPrincipal Principal
    {
        get { return (MyPrincipal)Thread.CurrentPrincipal; }
    }

    public MyIdentity Identity
    {
        get { return (MyIdentity)Thread.CurrentPrincipal.Identity; }
    }
}

      



If you want more access to these elements, you can create a simple object with static properties that do the same.

0


source







All Articles