Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Silverlight中合并样式?_Silverlight_Silverlight 3.0_Styles - Fatal编程技术网

如何在Silverlight中合并样式?

如何在Silverlight中合并样式?,silverlight,silverlight-3.0,styles,Silverlight,Silverlight 3.0,Styles,我的目标是扩展对象的已设置样式。假设我有以下两种风格: <Style TargetType="Ellipse" x:Key="OriginalStyle"> <Setter Property="Fill" Value="Blue"/> <Setter Property="Width" Value="100"/> <Setter Property="Height" Value="200"/> </Style> &l

我的目标是扩展对象的已设置样式。假设我有以下两种风格:

<Style TargetType="Ellipse" x:Key="OriginalStyle">
    <Setter Property="Fill" Value="Blue"/>
    <Setter Property="Width" Value="100"/>
    <Setter Property="Height" Value="200"/>
</Style>
<Style TargetType="Ellipse" x:Key="NewStyle">
    <Setter Property="Fill" Value="Red"/>
</Style>
我尝试动态构建一个新样式,并添加NewStyle和OldStyle的属性-但是样式的属性始终为空,因此这会导致一个死胡同:

Style combinedStyle = new Style();
foreach (Setter setter in Old.Setters)
{
     combinedStyle.Setters.Add(setter);  // Get exception "Element is already the child of another element."
}
foreach (Setter setter in NewStyle.Setters)
{
     combinedStyle.Setters.Add(setter);  // Get exception "Element is already the child of another element."
}

似乎无法在Silverlight中动态合并样式。有人能证实这一点或向我展示一种更好的实现合并的方法吗?

在Silverlight中“BasedOn”是否起作用wpf开发者,永远不要确定你可以这样做:-

<Style TargetType="Ellipse" x:Key="OriginalStyle">
    <Setter Property="Fill" Value="Blue"/>
    <Setter Property="Width" Value="100"/>
    <Setter Property="Height" Value="200"/>
</Style>
<Style TargetType="Ellipse" x:Key="NewStyle" BasedOn="{StaticResource OriginalStyle}">
    <Setter Property="Fill" Value="Red"/>
</Style>

请注意,这类
Style
元素的出现顺序很重要,不能基于XAML解析器尚未处理的内容创建样式

<Style TargetType="Ellipse" x:Key="OriginalStyle">
    <Setter Property="Fill" Value="Blue"/>
    <Setter Property="Width" Value="100"/>
    <Setter Property="Height" Value="200"/>
</Style>
<Style TargetType="Ellipse" x:Key="NewStyle" BasedOn="{StaticResource OriginalStyle}">
    <Setter Property="Fill" Value="Red"/>
</Style>