Hi,
I luckily found the problem! The real problem was the call to SetBinding() in line 13, which had no effect. But I actually forgot to set the attribute "[Microsoft.UI.Xaml.Data.Bindable]" in the IDL file!
namespace NetworkView
{
[Microsoft.UI.Xaml.Data.Bindable]
runtimeclass NodeViewModel : Microsoft.UI.Xaml.Data.INotifyPropertyChanged
{
// Declaring a constructor (or constructors) in the IDL causes the runtime class to be
// activatable from outside the compilation unit.
NodeViewModel();
String Name;
Double X;
Double Y;
}
}
void BindingHelperNodes::OnBindingPathPropertyChanged( winrt::Microsoft::UI::Xaml::DependencyObject const& d, winrt::Microsoft::UI::Xaml::DependencyPropertyChangedEventArgs const& e )
{
if(Microsoft::UI::Xaml::Controls::ListBoxItem item{ d.try_as<Microsoft::UI::Xaml::Controls::ListBoxItem>() })
{
Microsoft::UI::Xaml::Data::Binding binding;
binding.Mode( Microsoft::UI::Xaml::Data::BindingMode::OneWay );
Microsoft::UI::Xaml::PropertyPath propertyPath( L"X" );
binding.Path( propertyPath );
// Alternative 1 works
//Microsoft::UI::Xaml::Data::BindingOperations::SetBinding(
// d,
// Microsoft::UI::Xaml::Controls::Canvas::LeftProperty(),
// binding);
// Alternative 2 works, too
item.SetBinding( Microsoft::UI::Xaml::Controls::Canvas::LeftProperty(), binding );
}
}
Best regards
Alfred