Home Forums WPF controls Xceed Toolkit Plus for WPF How to call new ViewTemplate in AvalonDock?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #41775 |

    I am able to create new ViewTemplate:

    class SearchViewModel : ToolViewModel//I make SearchViewmodel to inherit from ToolViewModel
    {
        public DataTemplate SearchViewTemplate
        {
            get; set;
        }
    
        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            //The code omitted for brevity...
        }
    }

    and SearchViewTemplate:

    <avalonDock:DockingManager.LayoutItemTemplateSelector>
      <local:PanesTemplateSelector>
         <local:PanesTemplateSelector.FileViewTemplate>
             ...//The code omitted for brevity...
         </local:PanesTemplateSelector.FileViewTemplate>
      <local:PanesTemplateSelector.FileStatsViewTemplate>
             ...//The code omitted for brevity...
      </local:PanesTemplateSelector.FileStatsViewTemplate>
         <local:PanesTemplateSelector.SearchViewTemplate>
            <DataTemplate>
               <TextBlock Text="Hello World!:)"/>
            </DataTemplate>
         </local:PanesTemplateSelector.SearchViewTemplate>
      </local:PanesTemplateSelector>

    Code to show SearchViewTemplate Workspace.cs:

        SearchViewModel _searchViewModel = null;
        public SearchViewModel SearchHelper
        {
            get
            {
                if (_searchViewModel == null)
                    _searchViewModel = new SearchViewModel();
    
                return _searchViewModel;
            }
        }

    XAML to call template:

    <MenuItem Header="Tools">
       <MenuItem Header="Properties" IsChecked="{Binding FileStats.IsVisible, Mode=TwoWay}" IsCheckable="True"/>
       <MenuItem Header="Search Window" IsChecked="{Binding SearchHelper.IsVisible, Mode=TwoWay}" IsCheckable="True"/>
    </MenuItem>

    However, TextBlock with Text=”Hello World!:)” is not shown. How to show newly created ViewTemplate?

    Imported from legacy forums. Posted by Stepan (had 315 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    DockingManager has a property called “LayoutItemTemplateSelector”, which let you define the template selector to use for anchorable and document templates.

    From what I can see in the image you attached, this selector will be a “PanesTemplateSelector” class, defined locally on your end. From there, you try to set the PanesTemplateSelector.FileViewTemplate and PanesTemplateSelector.FileStatsViewTemplate properties.

    These properties are not part of AvalonDock or the Toolkit. I believe you will have to add a new ViewTemplate property in your PanesTemplateSelector class in order to create other ViewTemplates.

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 102 views)

    User (Old forums)
    Member
    Post count: 23064

    [quote user=”Fawzi [Xceed]”]Hi,
    DockingManager has a property called “LayoutItemTemplateSelector”, which let you define the template selector to use for anchorable and document templates.
    From what I can see in the image you attached, this selector will be a “PanesTemplateSelector” class, defined locally on your end. From there, you try to set the PanesTemplateSelector.FileViewTemplate and PanesTemplateSelector.FileStatsViewTemplate properties.
    These properties are not part of AvalonDock or the Toolkit. I believe you will have to add a new ViewTemplate property in your PanesTemplateSelector class in order to create other ViewTemplates.[/quote]

    Thanks for your reply! I’ve done it. I’ve done all actions in PanesTemplateSelector class. Please, see my question(the first message of this topic) again and you will see what I’ve done. However, new template cannot be seen in the run program. 

    <avalonDock:DockingManager.LayoutItemTemplateSelector>

                    <local:PanesTemplateSelector>

                        <local:PanesTemplateSelector.FileViewTemplate>

                            <DataTemplate>

                                <!–This FileViewTemplate is perfectly shown in my program. The code omitted for brevity–>

                            </DataTemplate>

                        </local:PanesTemplateSelector.FileViewTemplate>

                        <local:PanesTemplateSelector.FileStatsViewTemplate>

                            <DataTemplate>

                                <!–This FileStatsViewTemplate is perfectly shown in my program. The code omitted for brevity–>

                            </DataTemplate>

                        </local:PanesTemplateSelector.FileStatsViewTemplate>

                        <local:PanesTemplateSelector.SearchViewTemplate>

                            <DataTemplate>

                                <TextBlock Text=”Hello World!:)”/>

                                <!–This SearchViewTemplate is perfectly NOT shown in my program. What am I doing wrong?–> 

                            </DataTemplate>

                        </local:PanesTemplateSelector.SearchViewTemplate>

                    </local:PanesTemplateSelector>

                </avalonDock:DockingManager.LayoutItemTemplateSelector> 

    So I have two questions:

    1. Why is new template now shown in the run program. 

    2. Where or how can I assign place where new template will be shown?(For example, FileStatsViewTemplate is always shown at the left side of a Window at start of program) 

     Thanks!:)

     

     

     

    Imported from legacy forums. Posted by Stepan (had 83 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Stepan,

    Could you send me a complete sample project so that we can test the exact same code as yours. I can’t figure out what the class ToolViewModel is. It seems to be derived from DataTemplateSelector.

    In the meantime, I tried to create a sample based on your code. You can find it in attachment.

    1) In my sample, the dataTemplate “SearchViewTemplate” is shown when returned in PanesTemplateSelector.SelectTemplate method.

    2) Is the position of the DataTemplate content in the Window is just an alignment that needs to be set ? In the sample, the DataTemplate for “SearchViewTemplate” uses an HorizontalAlignment Right. Is this what you want ? 

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 48 views)

    User (Old forums)
    Member
    Post count: 23064
    Hi, Fawzi! 🙂
    When I click at the program AvalonDock.MVVMTestApp:
    1. “File -> New” – the program creates new window(FileViewTemplate) at the right side with each click. It is okay.
    2. “Tools -> Properties” – the program creates always one window(FileStatsViewTemplate) at the left side with each click. It is okay
    3. “Tools -> Search Window” – the program does not create any window(SearchViewTemplate). Where can I define the code to locate the position to show SearchViewTemplate when SearchViewModel is created at the program(at the left side or at the right side).
     
    What I did to create SearchViewModel: 
    1. I’ve created SearchViewTemplate at the PanesTemplateSelector class
    class SearchViewModel : ToolViewModel
        {  //I’ve pasted the code from  FileStatsViewModel class    }
     
    2 . I’ve declared SearchViewTemplate:
    <local:PanesTemplateSelector.SearchViewTemplate>
       <DataTemplate>
          <TextBlock Text=”Hello World”/>
       </DataTemplate>
    </local:PanesTemplateSelector.SearchViewTemplate> 
     
    3. I’ve added PaneStyleSelector:
    class PanesStyleSelector : StyleSelector    {
            …
            public Style SearchStyle
            {
                get;
                set;
            }
            public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
            {
                …..
                if (item is SearchViewModel)
                    return SearchStyle;
                return base.SelectStyle(item, container);
            }
        } 
     
    4. <avalonDock:DockingManager.LayoutItemContainerStyleSelector>
                    <local:PanesStyleSelector>
                        <local:PanesStyleSelector.ToolStyle>
                            <Style TargetType=”{x:Type avalonDock:LayoutAnchorableItem}”>
                                …..
                            </Style>
                        </local:PanesStyleSelector.ToolStyle>   
                        <local:PanesStyleSelector.FileStyle>
                            <Style TargetType=”{x:Type avalonDock:LayoutItem}”>
                                ….. 
                            </Style>
                        </local:PanesStyleSelector.FileStyle>
                        <local:PanesStyleSelector.SearchStyle>
                            <!– I’ve just copied the style from FileStyle. Is it normal? –> 
                            <Style TargetType=”{x:Type avalonDock:LayoutItem}”>
                                <Setter Property=”Title” Value=”{Binding Model.Title}”/>
                                <Setter Property=”ToolTip” Value=”{Binding Model.FilePath}”/>
                                <Setter Property=”CloseCommand” Value=”{Binding Model.CloseCommand}”/>
                                <Setter Property=”IconSource” Value=”{Binding Model.IconSource}”/>
                                <Setter Property=”ContentId” Value=”{Binding Model.ContentId}”/>
                            </Style>                       
                        </local:PanesStyleSelector.SearchStyle>
                    </local:PanesStyleSelector>
                </avalonDock:DockingManager.LayoutItemContainerStyleSelector>           
    Questions:
    1. Am I right to inherit from ToolViewModel to create another ViewTemplate(the third template SearchViewTemplate)?
    2. Is it possible to create three types of ViewTemplates(FileViewTemplate, FileStatsViewTemplate, SearchViewModel) simultaneously?
    3. Is it normal just copy style from FileStyle into SearchStyle? 
     
    I’ve attached my code. Please, see it, please:)

    Imported from legacy forums. Posted by Stepan (had 77 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    After running your sample application, I can see the problem.
    To be able to see the SearchViewTemplate, I did the 3 following modifications in your code.

    a) In Workspace.Tools property, I modified
    _tools = new ToolViewModel[] { FileStats };
    to
    _tools = new ToolViewModel[] { FileStats, SearchHelper };

    This way the SearchViewTemplate can be used as a Tools.

    b) To make the SearchViewTemplate visible, In file MainWindow.xaml, for local:PanesStyleSelector.SearchStyle, I modify the binding for Visibility from
    Model.IsVisible to Model.IsVisibleSearch.

    This way, the correct property gets binded for the SearchViewModel.

    c) In PanesStyleSelector.SelectStyle, I move the “if” condition for the ToolViewModel after the “if” conditions of FileViewModel and SearchViewModel. It results in this :
    if (item is FileViewModel)
                    return FileStyle;
    if (item is SearchViewModel)
                    return SearchStyle;
    if( item is ToolViewModel )
            return ToolStyle;

    return base.SelectStyle(item, container);

    Since SearchViewModel is a ToolViewModel, having the ToolViewModel condition first would always do action for ToolViewModel.
    FileStatsViewModel is a ToolViewModel, action will be done on ToolViewModel.
    FileViewModel has its own condition.

    The answers to your questions :

    1. Am I right to inherit from ToolViewModel to create another ViewTemplate(the third template SearchViewTemplate)?
    There is no problem with that.

    2. Is it possible to create three types of ViewTemplates(FileViewTemplate, FileStatsViewTemplate, SearchViewModel) simultaneously?
    Yes.

    3. Is it normal just copy style from FileStyle into SearchStyle?
    It’s ok, but make sure to use the wanted properties for binding (example : IsVisibleSearch for SearchStyle’s Visibility).

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 57 views)

    User (Old forums)
    Member
    Post count: 23064

    Fawzi, Thank you very much!!!

    A lot! 🙂 

    Man, you are awesome programmer!!!

    Imported from legacy forums. Posted by Stepan (had 105 views)

    User (Old forums)
    Member
    Post count: 23064

    Fawzi, I’ve found very strange behavior of FileStatsViewTemplate.

    1. If I click “Tools->Properties” , it creates new FileStatsViewTemplate and all FileStatsViewTemplates are ordered in a LayoutDocumentPane.

    But I would like just have one “FileStats”, It is not depend on how many an user clicks at “Files->Properties”

    enter image description here 

    2. I would like to load FileStatsViewTemplate at first, not SearchViewTemplate. At start of program I always see SearchViewTemplate at first, however I would like to show FileStats at first, and no SearchViewTemplate till an user clicks “Tools->SearchWindow”.

    It is really shameful, but I’ve spent 2 days and cannot figured out how to solve this tasks. Help me, please, Fawzi.

     

    Imported from legacy forums. Posted by Stepan (had 52 views)

    Fawzi [Xceed]
    Member
    Post count: 722
    Hi Stepan,
    1) Multi FileStats tab
    On every load of the application, a new FileStats tab is added. This is because the “ToolContentId” is the same for the SearchViewModel and the FileStatsViewModel. Simply replace the following line in your SearchViewModel.cs :
    public const string ToolContentId = “FileStatsTool”;
    for
    public const string ToolContentId = “SearchTool”;
    Make sure to remove the “AvalonDock.config” file before next start of the Application.
    2) Load application without SearchViewTemplate
    The visibility of your templates is binded with property “IsVisible” (for FilStats) and property “IsVisibleSearch” for Search. In ToolViewModel.cs, the variables “_isVisible” and “_isVisibleSearch” are both true by default. Simply set “_isVisibleSearch = false”. You will load your application with only the FileStats template.

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 71 views)

    User (Old forums)
    Member
    Post count: 23064

    Fawzi [Xceed], thanks a lot. You are awesome! Thanks you very much!

    Imported from legacy forums. Posted by Stepan (had 211 views)

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.