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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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,
i'm using VS2019(last version), .NetCore3.1 Wpf Application.
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.