我的 App.xaml 文件中有几个样式定义。像这样:
<Application x:Class="MyClient.App" ... >
    <Application.Resources>
        <SolidColorBrush x:Key="color1" Color="#FF7D7D" />
        <SolidColorBrush x:Key="color2" Color="#FF7D7E" />
        <Style x:Key="styleFor1" TargetType="charting:ColumnDataPoint">
            <Setter Property="Background" Value="{StaticResource color1}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:ColumnDataPoint">
                        <Grid>
                            <Rectangle>
                                <Rectangle.Fill>
                                    <LinearGradientBrush>
                                        <GradientStop Color="#ffff3737" Offset="0" />
                                        <GradientStop Color="#80000000" Offset="1" />
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <ToolTipService.ToolTip>
                                <StackPanel>
                                    <ContentControl Content="VALUES:" FontWeight="Bold" />
                                    <ContentControl Content="{TemplateBinding FormattedIndependentValue}" />
                                    <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
                                </StackPanel>
                            </ToolTipService.ToolTip>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
我生成一个图表。并给它的 DataPointStyle 这个:
Style dpStyle = Application.Current.Resources["styleFor1"]
之后,我想在这个 dpStyle 中添加更多的 Setter。完成后,我将图表的 DataPointStyle 设置为此 dpStyle。然后我得到了例外。我应该怎么办?请指导我。
更新:
异常详细信息(可能需要):
InvalidOperationException 未处理
{“‘SetterBaseCollection’在使用(密封)后,不能修改。”}
目标站点:{无效 CheckSealed()}