Wpf 在windows phone中绑定属性源更改时如何呈现(重绘)usercontrol

Wpf 在windows phone中绑定属性源更改时如何呈现(重绘)usercontrol,wpf,xaml,windows-phone-8,user-controls,Wpf,Xaml,Windows Phone 8,User Controls,我在Windows Phone中构建了一个控件(相同的WPF),按时间线绘制垂直图表。 在Xaml中: 怎么做?谢谢 在usercontrol中创建自定义事件 private event ItemsSourceChanged; 添加所有必需的代码以支持事件更改 现在触发属性更改事件 public IEnumerable<ITimelineData> ItemSource { get { return base.GetValue(ItemSourceProperty) as

我在Windows Phone中构建了一个控件(相同的WPF),按时间线绘制垂直图表。 在Xaml中:

怎么做?谢谢

  • 在usercontrol中创建自定义事件

    private event ItemsSourceChanged;
    
  • 添加所有必需的代码以支持事件更改
  • 现在触发属性更改事件

    public IEnumerable<ITimelineData> ItemSource
    {
        get { return base.GetValue(ItemSourceProperty) as IEnumerable<ITimelineData>; }
        set { base.SetValue(ItemSourceProperty, value); OnItemSourcePropertyChange(); }
    }
    
    public IEnumerable ItemSource
    {
    获取{return base.GetValue(ItemSourceProperty)作为IEnumerable;}
    set{base.SetValue(ItemSourceProperty,value);OnItemSourcePropertyChange();}
    }
    
  • 在xaml中,将事件映射到代码隐藏并进行更改

    <myControl:VerticalChart ItemSource="{Binding ActivitiesToday}" ItemSourceChanged="doSomething" />
    
    
    
  •  Border border = new Border();
     border.Width = borderWidth;
     border.Height = ran.Next(100, 250);
    
     Binding binding = new Binding("Foreground");
     binding.Source = this;
     border.SetBinding(Border.BackgroundProperty, binding);
    
     double top = height - border.Height;
     Canvas.SetLeft(border, left);
     Canvas.SetTop(border, top);
     canvasRender.Children.Add(border);
    
    private event ItemsSourceChanged;
    
    public IEnumerable<ITimelineData> ItemSource
    {
        get { return base.GetValue(ItemSourceProperty) as IEnumerable<ITimelineData>; }
        set { base.SetValue(ItemSourceProperty, value); OnItemSourcePropertyChange(); }
    }
    
    <myControl:VerticalChart ItemSource="{Binding ActivitiesToday}" ItemSourceChanged="doSomething" />