惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
博客园 - 叶小钗
N
Netflix TechBlog - Medium
罗磊的独立博客
量子位
MyScale Blog
MyScale Blog
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
B
Blog
腾讯CDC
爱范儿
爱范儿
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
雷峰网
雷峰网
G
Google Developers Blog
Google DeepMind News
Google DeepMind News

博客园 - sh37

Newtonsoft中的几个妙用 Mvc中ViewData与TempData的区别 Silverlight中利用ListBox特性实现单选按钮组RadioButtonList和复选按钮组CheckBoxList的功能 cookie操作 - sh37 - 博客园 C# 利用net 命令获取域用户列表 - sh37 利用MessageQueue收发消息 - sh37 - 博客园 C# xmlhttp - sh37 - 博客园 使用ASP获得AD帐号 “域\用户名” - sh37 - 博客园 使用ASP.NET获得AD帐号 - sh37 - 博客园 根據xml文檔數據 給DataTable增加行 JS获取剪贴板内容的代码 - sh37 - 博客园 分页时使当前页码变色 C#生成缩略图 自動生成帶文字的圖片 常用pl/sql vb.net後台抓取網頁內容 ServerVariables集合内容列表 如何动态创建一个按纽 并给这个按纽绑上一个Onclick事件 17种常用正则表达式
SilverLight中Page也可使用泛型基类
sh37 · 2011-10-18 · via 博客园 - sh37

最近在用SilverLight+MVC做项目时碰到问题,以往用Asp.net中WebForm做项目时都会在项目框架中使用继承自Page的泛型基类来实现增、删、查、改等基础方法。

但在SilverLight却无法使用,如以下代码无法成功编译

 public partial class CodeClassManage: SysPageBase<CodeClass>

{

//.......

}

//其基类SysPageBase实现了增、删、查、改等基础方法

public partial class SysPageBase<T> : Page
        where T:Entity,new()

{

//实现增、删、查、改等基础方法的过程略过

//...

}

因为CodeClassManage页面文件如下

<Bis:SysPageBase  x:Class="SLApp.CodeClassManage" 

Bis="clr-namespace:SLApp;assembly=SLApp"
    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"
    mc:Ignorable="d" >

 </Bis:SysPageBase>

红色代码部分无法使用泛型。

 在网上找了很久也未找到解决办法。于是想到了使用中间类来转一下,以上代码变为

public partial class CodeClassManage : TCodeClassManage
 {

//.....

}

//以下为多出来的中间类,其内容可为空

 public partial class TCodeClassManage: SysPageBase<CodeClass>

{

}

//其基类SysPageBase实现了增、删、查、改等基础方法

public partial class SysPageBase<T> : Page
        where T:Entity,new()

{

//实现增、删、查、改等基础方法的过程略过

//...

}

CodeClassManage页面文件如下

<Bis:TCodeClassManage x:Class="SLApp.CodeClassManage" 

Bis="clr-namespace:SLApp;assembly=SLApp"
    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"
    mc:Ignorable="d" >

 </Bis:TCodeClassManage >

 以上达到使用泛型基类的目的,虽然多出了个中间类TCodeClassManage ,但其内容可为空,还是可以忽略不记的。