Silverlight 窗体继承 怎么用?
原因:WPF窗体继承和winform窗体继承存在差异。
网上找到的WPF继承方法:创建基类BaseFrm,动态设置其样式。 可是报错:值不在预期的范围内。
代码如下:
[StyleTypedProperty(Property = "DefaultStyleKey", StyleTargetType = typeof(BaseFrm))] public class BaseFrm:UserControl { public BaseFrm() { this.DefaultStyleKey = typeof(BaseFrm); [color=#FF0000]//这里报错: 值不在预期的范围内。[/color] } }样式定义Generic.xaml:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SLInheritWindow"> <Style TargetType="local:BaseFrm"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:BaseFrm"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style></ResourceDictionary>