【问题标题】:Not able to change WPF Toolkit Area Series background无法更改 WPF 工具包区域系列背景
【发布时间】:2015-10-15 05:47:46
【问题描述】:

我正在使用 WPF Toolkit 面积图控件。我无法将区域系列的背景更改为任何其他颜色。它只是分配颜色代码#FFFFA500。

我的 XAML 代码如下

            <chartingToolkit:Chart.Palette x:Uid="tt">
                <datavis:ResourceDictionaryCollection>
                    <ResourceDictionary>
                        <Style x:Key="DataPointStyle" TargetType="Control">
                            <Setter Property="Background" Value="#FF3EA0C0"/>
                        </Style>
                    </ResourceDictionary>
                    <ResourceDictionary>
                        <Style x:Key="DataPointStyle" TargetType="Control">
                            <Setter Property="Background" Value="#FF44C8F5"/>
                        </Style>
                    </ResourceDictionary>
                </datavis:ResourceDictionaryCollection>
            </chartingToolkit:Chart.Palette>

            <chartingToolkit:Chart.LegendStyle>
                <Style TargetType="Control">
                    <Setter Property="Width" Value="0"/>
                    <Setter Property="Height" Value="0"/>
                </Style>
            </chartingToolkit:Chart.LegendStyle>

            <chartingToolkit:AreaSeries Background="Black" x:Name="SecondSeries" DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True">

                <chartingToolkit:AreaSeries.DataPointStyle>
                    <Style TargetType="chartingToolkit:AreaDataPoint">

                        <Setter Property="IsTabStop"  Value="False" />
                        <Setter Property="Width" Value="Auto" />
                        <Setter Property="Height" Value="30" />                                                                                                                                        
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="chartingToolkit:AreaDataPoint">
                                    <Button Name="pointButton" Content="{Binding}" Click="pointButton_Click_1" BorderThickness="1" >
                                        <Button.Template>
                                            <ControlTemplate>
                                                <StackPanel>

                                                    <TextBlock Text="{Binding Path=Value}" Cursor="Hand"></TextBlock>

                                                </StackPanel>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>

                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </chartingToolkit:AreaSeries.DataPointStyle>
                <chartingToolkit:AreaSeries.DependentRangeAxis>
                    <chartingToolkit:LinearAxis Orientation="Y" FontFamily="Rockwell" Title="Expenses" FontSize="14" >

                    </chartingToolkit:LinearAxis>
                </chartingToolkit:AreaSeries.DependentRangeAxis>
            </chartingToolkit:AreaSeries>
        </chartingToolkit:Chart>

请帮帮我。这让我发疯了。

【问题讨论】:

标签: wpf xaml wpftoolkit


【解决方案1】:

问题在于AreaSeries 控件模板中有一个Grid,它应用了一种样式,将背景设置为LinearGradientBrush

为了改变绘图区域的背景,添加这个样式

<Style TargetType="Grid" x:Key="plotStyle">
    <Setter Property="Background">
        <Setter.Value>
            <SolidColorBrush Color="Pink"/>
        </Setter.Value>
    </Setter>
</Style>

并将其用作 Chart 控件的 PlotAreaStyle

<chartingToolkit:Chart Background="Black" PlotAreaStyle="{StaticResource plotStyle}">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-15
    • 2011-10-15
    • 1970-01-01
    相关资源
    最近更新 更多