C# Devexpress DXCharts(刷新、更新、清除)新实例?

C# Devexpress DXCharts(刷新、更新、清除)新实例?,c#,wpf,charts,devexpress,dependency-properties,C#,Wpf,Charts,Devexpress,Dependency Properties,我正在第三方DevExpress库中使用wpf和c。我对DX图表有问题。我尝试了一些不同的方法来清除或更新图表,但都没有效果。我正在使用数据源的依赖属性将数据绑定到数据表(动态构建) 将新数据设置为备份属性时,图表的依赖项属性似乎不会被覆盖。这给了我图表上的重叠点。正如您在下面的示例中所看到的 第一组数据 第二组数据 我还尝试创建图表控件的新实例,它仍然显示旧的绑定依赖属性。DXchart用户控件嵌入到内容控件中。我通过内容属性绑定图表。所有这些都嵌套在DevExpress选项卡控件下 下面

我正在第三方DevExpress库中使用wpf和c。我对DX图表有问题。我尝试了一些不同的方法来清除或更新图表,但都没有效果。我正在使用数据源的依赖属性将数据绑定到数据表(动态构建)

将新数据设置为备份属性时,图表的依赖项属性似乎不会被覆盖。这给了我图表上的重叠点。正如您在下面的示例中所看到的

第一组数据

第二组数据

我还尝试创建图表控件的新实例,它仍然显示旧的绑定依赖属性。DXchart用户控件嵌入到内容控件中。我通过内容属性绑定图表。所有这些都嵌套在DevExpress选项卡控件下

下面是一些代码:

依赖项属性

public static readonly DependencyProperty DataTableChartProperty = DependencyProperty.Register
        ("DataTableChart", typeof(DataTable), typeof(MainWindowViewModel));

public static readonly DependencyProperty ContentElementProperty = DependencyProperty.Register
        ("ContentElement", typeof(FrameworkElement), typeof(MainWindowViewModel));
public DataTable DataTableChart
    {
        get { return (DataTable)this.GetValue(DataTableChartProperty); }
        set { this.SetValue(DataTableChartProperty, value); }

public FrameworkElement ContentElement
    {
        get { return (FrameworkElement)this.GetValue(ContentElementProperty); }
        set { this.SetValue(ContentElementProperty, value); }
    }
支持属性

public static readonly DependencyProperty DataTableChartProperty = DependencyProperty.Register
        ("DataTableChart", typeof(DataTable), typeof(MainWindowViewModel));

public static readonly DependencyProperty ContentElementProperty = DependencyProperty.Register
        ("ContentElement", typeof(FrameworkElement), typeof(MainWindowViewModel));
public DataTable DataTableChart
    {
        get { return (DataTable)this.GetValue(DataTableChartProperty); }
        set { this.SetValue(DataTableChartProperty, value); }

public FrameworkElement ContentElement
    {
        get { return (FrameworkElement)this.GetValue(ContentElementProperty); }
        set { this.SetValue(ContentElementProperty, value); }
    }
用户控制

<UserControl x:Class="Reporting_DIMS.UI.ChartControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
         xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
         xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
         xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
         xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
         mc:Ignorable="d"
         d:DesignHeight="700" d:DesignWidth="1100">
<Grid>
    <Border Padding="3">
        <dxc:ChartControl Margin="0" Name="chartControl" DataSource="{Binding DataTableChart}">
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D SeriesDataMember="DIMS User">
                    <dxc:XYDiagram2D.SeriesTemplate>
                        <dxc:BarSideBySideSeries2D ValueDataMember="Count" ArgumentDataMember="Entry DateTime" />
                    </dxc:XYDiagram2D.SeriesTemplate>
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
            <dxc:ChartControl.Legend>
                <dxc:Legend x:Name="legend"/>
            </dxc:ChartControl.Legend>
        </dxc:ChartControl>
    </Border>
</Grid>

小的主窗口部分

<dx:DXTabItem Header="Log Charts" Name="dXTabItem2">
                    <ContentControl x:Name="contentControl" Content="{Binding     ContentElement}"/>
                </dx:DXTabItem>


如果有人有任何想法,我将不胜感激。提前谢谢

我最终删除了旧的图表对象并创建了一个新的。这是每个DevExpress图表的预期行为。

rreeves是正确的。对我来说,一个简单的解决方法是将DXChartControl包装在第二个ContentControl中。与其直接绑定到ChartControl,不如让内部ContentControl将绑定交给ChartControl,这样,当内容发生更改时,ContentControl将通过ContentTemplate生成一个新实例

    <DataTemplate x:Key="chartTemplate">
        <dex:ChartControl DataSource="{Binding}" DataContextChanged="chartControl_DataContextChanged_1"/>
    </DataTemplate>     
    <ContentControl  Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=chartTemplate}" Content="{Binding 'YOUR ITEMSSOURCE'}"/>

然后可以在DataContextChanged中重新构建图表


希望这有帮助

我发现这个问题与依赖属性完全无关。我将陈旧数据粘在正在迁移到新数据表的数据集中。我刚刚创建了一个新实例,一切正常。