C# 清除依赖项属性
从标准属性更新依赖属性时遇到一些问题 如果我将属性设置为null或使用新数据更新它,我的印象是它将重置依赖性属性。然而,看起来它只是把新数据堆在上面 下面是我正在使用的几个属性/依赖性属性: 依赖项属性C# 清除依赖项属性,c#,wpf,dependency-properties,C#,Wpf,Dependency Properties,从标准属性更新依赖属性时遇到一些问题 如果我将属性设置为null或使用新数据更新它,我的印象是它将重置依赖性属性。然而,看起来它只是把新数据堆在上面 下面是我正在使用的几个属性/依赖性属性: 依赖项属性 public static readonly DependencyProperty DataTableChartProperty = DependencyProperty.Register ("DataTableChart", typeof(DataTable), typeof(Main
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); }
}
如有任何建议,我将不胜感激。提前谢谢
这就是我现在设置的方式。。。用于测试
void _bw_DoWork(object sender, DoWorkEventArgs e)
{
var loadLog = new LoadLog();
e.Result = loadLog.LoadCaseLogs(SelectedFiles);
}
void _bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
DataTableChart = null;
ContentElement = null;
ContentElement = blah;
DataTableResult = e.Result as DataTable;
DataTableChart = caseData.LoadUserData(DataTableResult);
LoadingScreen = false;
}
public ChartControl blah = new ChartControl();
使用该方法清除依赖项属性,将其设置为
null
只是将其设置为null
,这是不同的。使用该方法清除依赖项属性,将其设置为null
只是将其设置为null
,这是不一样的。它看起来只是把新数据堆在上面,这是什么意思?请告诉我们您是如何设置属性的,因为这没有多大意义。调用DataTableChart=null
应该就是你所需要的了。我试着把它设置为null,但我不知道它看起来像是在上面堆新数据,这是什么意思?请告诉我们您是如何设置属性的,因为这没有多大意义。调用DataTableChart=null
应该是您所需要的。我只是尝试将其设置为null,但对meso不起作用。我会执行类似于blah.clearvalue(DataTableChart)的操作吗?@rreeves:是的,除了传递属性字段,即DataTableChartProperty
。我会执行类似于blah.clearvalue(DataTableChart)的操作吗?@rreeves:是,除了传递属性字段,即DataTableChartProperty
。