custom canvas with itemssource

essamce 621 Reputation points
2020-11-12T08:16:28.23+00:00

hi,
i'm trying to create custom canvas with bindable itemsource of type object, i did the following:

         public IList<object> Items { get; private set; }

        public IEnumerable ItemsSource
        {
            get { return Items; }
            set
            {
                if (value == null)
                {
                    ClearValue(ItemsSourceProperty);
                }
                else
                {
                    SetValue(ItemsSourceProperty, value);
                }
            }
        }


        public static readonly DependencyProperty ItemsSourceProperty
            = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(CanvasSupportsMovableWithItemsSource),
                 new FrameworkPropertyMetadata((IEnumerable)null, new PropertyChangedCallback(OnItemsSourceChanged)));

        private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
... ??

but i don't know how to implement OnItemsSourceChanged,
any help will be appreciated,

thanks in advance.

i'm using VS2019(last version), .NetCore3.1 Wpf Application.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,760 questions
0 comments No comments
{count} votes

Accepted answer
  1. DaisyTian-1203 11,621 Reputation points
    2020-11-13T07:15:52.843+00:00

    You can refer to below example code to implement your code on needs:

      private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)  
            {  
                if (d != null && d is CanvasSupportsMovableWithItemsSource)  
                {  
                    CanvasSupportsMovableWithItemsSource source = (CanvasSupportsMovableWithItemsSource)d;  
                    source.ItemsSource = (IEnumerable)e.NewValue;  
                }  
            }  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.