xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.9k stars 877 forks source link

DockingManager.ActiveContent binding doesn't work #1738

Open fasttester opened 1 year ago

fasttester commented 1 year ago

Binding from ActiveContent in XAML

(Xceed.Wpf.AvalonDock.DockingManager, ActiveContent="{Binding SelectedContent, Converter={StaticResource ActiveDocumentConverter}, Mode=TwoWay}" )

it doesn't work(does not trigger) in the new version 4.5.22477.12540 (Xceed.Products.Wpf.Toolkit.Full)

in kombination with CommunityToolkit.Mvvm 8.1.0.

But in older versions( for example version 4.1.21122.16390) it worked.

XceedBoucherS commented 1 year ago

Hi, Could you submit a sample so we could teste the same scenario as you ? What exactly is your SelectedContent you are trying to bind to ? Was this an issue in other versions ? v4.2, v4.3 or v4.4 ? Thank you

fasttester commented 1 year ago

hi XceedBoucherS,

thanks for your reply, the problem with binnding appeared only in the new version (Xceed.Products.Wpf.Toolkit.Full 4.5.22477.12540), in version 4.4.22258.9000 (and all earlier versions)everything was still fine.

Binding between: MainWindow.xaml

...ActiveContent="{Binding SelectedContent...

and

MainWindowViewModel.cs:

_.... public object SelectedContent { get { return _selectedContent; } set { if (selectedContent != value) ....

it doesn't work anymore. When selecting a new context (windows or tabs), the property will not be affected, as if the binding no longer exists. The behavior is the same with every code we tried but if no one else has the same problem i can send you my test code.

fasttester commented 1 year ago

AvalonDockDockingManagerActiveContentTests.zip

XceedBoucherS commented 1 year ago

Hi,

Thank you for your sample. It was much easier to test your scenario.

v4.5 included a fix to prevent a bug happening on the click of a TabItem. We could receive 2 indexes instead of only the wanted one. Basically, the ActiveContent now returns the LayoutContent instead of the LayoutContent.Content.

Here's your workaround: Try using your ActiveDocumentConverter this way: `public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if( value == null ) return value;

  var layoutContent = value as LayoutContent;
  if( ( layoutContent != null ) 
            && (( layoutContent.Content is DockWindowViewModel ) || ( layoutContent.Content == null ) ) )
    return value;
  //if (value is DockWindowViewModel|| value == null)
  //    return value;

  return Binding.DoNothing;
    }

    public object ConvertBack(object value, Type targetType, object parameter,
                                                        System.Globalization.CultureInfo culture)
    {
  if( value == null )
    return value;

  var layoutContent = value as LayoutContent;
        if( ( layoutContent != null )
            && (( layoutContent.Content is DockWindowViewModel ) || ( layoutContent.Content == null ) ) )
            return value;
        //if (value is DockWindowViewModel || value == null)
        //  return value;

        return Binding.DoNothing;
    }`

Thank you