我有这个自己的课程:
public class PeriodContainerPanel:StackPanel
{
public PeriodContainerPanel()
: base()
{
addCollectionsToStackPanel();
}
private void addCollectionsToStackPanel()
{
this.Children.Clear();
if (PeriodsList!=null)
{
double minutes = PeriodsList.Count * (Properties.Settings.Default.EndTimeSpan - Properties.Settings.Default.StartTimeSpan).TotalMinutes;
foreach (ObservableCollection<PeriodBase> lst in PeriodsList)
{
this.Children.Add(new ChartUserControl(lst) { Minutes = minutes });
}
}
}
public List<ObservableCollection<PeriodBase>> PeriodsList
{
get { return (List<ObservableCollection<PeriodBase>>)GetValue(PeriodsListProperty); } //do NOT modify anything in here
set { SetValue(PeriodsListProperty, value); addCollectionsToStackPanel(); } //...or here
}
public static readonly DependencyProperty PeriodsListProperty =
DependencyProperty.Register(
"PeriodsList", //Must be the same name as the property created above
typeof(List<ObservableCollection<PeriodBase>>), //Must be the same type as the property created above
typeof(PeriodContainerPanel), //Must be the same as the owner class
new UIPropertyMetadata(
null //default value, must be of the same type as the property
));
}
我像这样使用DependencyProperty
PeriodList
它UserControl
:
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<UI:PeriodContainerPanel PeriodsList="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=DataContext}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
我检查Convertor
是否有任何获取过程(如果有价值)是的有价值并且它是正确的,但它没有设置为PeriodsList
属性。什么是问题?PS如果对代码有任何疑问,请告诉我,我可以添加