我正在使用Caliburn.Micro框架構建我的應用程序。我試圖創建一個從WPF工具包圖表派生的自定義圖表控件,它需要添加2個自定義依賴項屬性。Caliburn.Micro和自定義依賴項屬性不起作用
由於某些原因,Caliburn.Micro未正確綁定到我創建的DP,但對現有的DP正常工作。我是否需要爲CM識別這些附加屬性?
(。在我的例子中,結合Title="{Binding ChartSeriesType}"
正常工作的ChartData
和ChartType
未更新)
SampleChart.xaml.cs
public partial class SampleChart : Chart
{
public ChartSeriesType ChartType
{
get { return (ChartSeriesType)GetValue(ChartTypeProperty); }
set
{
SetValue(ChartTypeProperty, value);
dataChaged();
}
}
// Using a DependencyProperty as the backing store for ChartType. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ChartTypeProperty =
DependencyProperty.Register("ChartType", typeof(ChartSeriesType), typeof(SampleChart), new UIPropertyMetadata(null));
public AgilityTableBase ChartData
{
get { return (AgilityTableBase)GetValue(ChartDataProperty); }
set
{
SetValue(ChartDataProperty, value);
dataChaged();
}
}
// Using a DependencyProperty as the backing store for ChartData. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ChartDataProperty =
DependencyProperty.Register("ChartData", typeof(AgilityTableBase), typeof(SampleChart), new UIPropertyMetadata(null));
private void dataChaged()
{
Console.WriteLine("data changed");
}
}
SampleChartView.xaml:
<UserControl x:Class="Agility.Presentation.ReportViewing.SampleChartView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cal="http://www.caliburnproject.org"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Agility.Presentation.ReportViewing"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="300"
d:DesignWidth="300" mc:Ignorable="d">
<local:SampleChart Title="{Binding ChartSeriesType}" ChartData="{Binding ReportTable}" ChartType="{Binding ChartSeriesType}" />
S ampleChartViewModel.cs:
public class SampleChartViewModel : PropertyChangedBase
{
private ChartSeriesType _chartType;
private SampleTableBase _reportTable;
public SampleChartViewModel(SampleTableBase reportTable)
{
_reportTable = reportTable;
}
public SampleTableBase ReportTable
{
get { return _reportTable; }
set
{
_reportTable = value;
this.NotifyOfPropertyChange(() => ReportTable);
}
}
public ChartSeriesType ChartSeriesType
{
get { return _chartType; }
set
{
_chartType = value;
this.NotifyOfPropertyChange(() => ChartSeriesType);
}
}
}
編輯
註冊ChartType DependencyProperty
是正確的方法:現在
// Using a DependencyProperty as the backing store for ChartType. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ChartTypeProperty =
DependencyProperty.Register("ChartType", typeof(ChartSeriesType), typeof(AgilityChart), new UIPropertyMetadata(ChartSeriesType.Bar
, new PropertyChangedCallback(dataChanged)));
private static void dataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Console.WriteLine("data changed");
}
,該dataChanged()
方法被調用。
我不太喜歡你在代碼中使用這個屬性的地方。正如我所看到的,您可以添加到一個圖表,許多系列每個都有不同的類型和字符類型,什麼都不做。 – Rafal
哎呀,我實際上並不想將'AddSeries'方法發佈到這個問題上,它現在沒有做任何事情。 – ChandlerPelhams