Home Forums WPF controls Other WPF controls Avalon Dock: Data bound title works in designer, but not when running app

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • rabjen-iwes
    Participant
    Post count: 8
    #44491 |

    I am currently trying to create a UI using Avalon Dock from Xceed WPF Toolkit 3. I created a much simpler version of this example. Basically, my view model looks like this:

    namespace NonWorkingAvalonDock {
    
        public sealed class MainViewModel {
    
            public MainViewModel() {
                Pages = new SimplePageViewModel[] {
                    new SimplePageViewModel("Foo"),
                    new SimplePageViewModel("Bar")
                };
            }
    
            public SimplePageViewModel[] Pages { get; }
        }
    
        public sealed class SimplePageViewModel {
    
            public SimplePageViewModel(string title) {
                Title = title;
            }
    
            public string Title { get; }
        }
    }

    And my XAML looks like this:

    <Window x:Class="NonWorkingAvalonDock.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:NonWorkingAvalonDock"
            xmlns:dock="http://schemas.xceed.com/wpf/xaml/avalondock"
            xmlns:dockctrl="clr-namespace:Xceed.Wpf.AvalonDock.Controls;assembly=Xceed.Wpf.AvalonDock"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <local:MainViewModel x:Key="ViewModel" />
        </Window.Resources>
        <dock:DockingManager DataContext="{StaticResource ViewModel}" AnchorablesSource="{Binding Pages}" >
            <dock:DockingManager.LayoutItemContainerStyle>
                <!-- you can add additional bindings from the layoutitem to the DockWindowViewModel -->
                <Style TargetType="{x:Type dockctrl:LayoutItem}" >
                    <Setter Property="Title" Value="{Binding Model.Title}" />
                </Style>
            </dock:DockingManager.LayoutItemContainerStyle>
        </dock:DockingManager>
    </Window>

    When I look at the result in the Designer, It looks alright:

    But when I run my application, the headers and titles are missing:

    What is going wrong here?

    rabjen-iwes
    Participant
    Post count: 8

    Followup

    I investigated the example and my code a bit more, and in the example, the author sets the data context in code behind. When I do this, it works for me, too.

    Moreover, I did the following experiment: I made the Pages property privately writable, initialized it with null and used a Timer which sets the view models after one second. When I do this, I get the titles, too.

    Is this a bug or do I have to do some additional stuff to make the binding appear without codebehind?

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    This will be fixed in v3.3.

    In the meantime, you can go in file Xceed.Wpf.AvalonDock/DockingManager.cs,
    in method “CreateAnchorableLayoutItem”,
    Replace :

    if (_layoutItems.Any(item => item.LayoutElement == contentToAttach))
    return;

    with :

    if( _layoutItems.Any( item => item.LayoutElement == contentToAttach ) )
    {
    foreach( var item in _layoutItems )
    {
    ApplyStyleToLayoutItem( item );
    }
    return;
    }

    Diane [Xceed]
    Moderator
    Post count: 1353

    Toolkit v3.3 is now available, and includes the following fix:

    In AvalonDock, using a style selector (property DockingManager.LayoutItemContainerStyleSelector) with the DockingManager.DocumentsSource property will now apply the desired style.

    Download Link: https://xceed.com/latest-xceed-toolkit-plus-for-wpf

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.