Self-regulation of general type restrictions and XAML in a UWP application

I am currently working on a UWP application in which I use general type restriction self-regulation in PCL.

Here is a description of the PCL classes.

First, a class that implements a generic type binding with self-regulation (this class also implements constraints new())

public abstract class A<T> 
  where T : A<T>, new()
{
  //...
}

Then I have a base class that extends the class Windows.UI.Xaml.Controls.Page:

public abstract class MyPage<T> : Page
  where T : A<T>, new()
{
  //...
}

I also have a base class that extends the class Windows.UI.Xaml.Application:

public abstract class MyApplication<T> : Application
  where T : A<T>, new()
{
  //...
}

My UWP classes extend the PCL classes described above as follows ...

Firstly, I have a class Bthat extends the class A:

public sealed class B : A<B>
{
  //...
}

Then I have a class Appthat extends the class MyApplication. Csharp file:

public sealed partial class App : MyApplication<B>
{
  //...
}

And the XAML file:

<custom:MyApplication
  x:Class="My.Project.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:custom="using:My.PCL"
  RequestedTheme="Light"
/>

HomePage, MyPage. csharp:

public sealed partial class HomePage : MyPage<B>
{
  //...
}

XAML:

<custom:MyPage
  x:Class="My.Project.HomePage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:custom="using:My.PCL"
  mc:Ignorable="d"
>

, ( , ):

MyApp<T> 1 ( App.i.cs)

MyPage<T> 1 ( HomePage.i.cs)

MyApp using:My.PCL ( App.xaml)

MyPage using:My.PCL ( HomePage.xaml)

genereic type XAML App HomePage, XAML :

<custom:MyApplication
  x:Class="My.Project.App"
  x:TypeArguments="local:B"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:custom="using:My.PCL"
  xmlns:local="using:My.Project"
  RequestedTheme="Light"
/>

<custom:MyPage
  x:Class="My.Project.HomePage"
  x:TypeArguments="local:B"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:custom="using:My.PCL"
  xmlns:local="using:My.Project"
  mc:Ignorable="d"
>

. ... :

GenericArguments [0], System.Object, My.PCL.MyApplication'1[T] T ( App.xaml)

GenericArguments [0], System.Object, My.PCL.MyPage'1[T] T ( HomePage.xaml)

- ?

!

+4
1

( Windows 8) , , , XAML - Windows 10.

:

public abstract class BaseApp : MyApplication<B>
{        
}

:

sealed partial class App : BaseApp

XAML :

<local:BaseApp
    x:Class="My.Project.App"

, , , .

+8

Source: https://habr.com/ru/post/1614634/


All Articles