Code Monkey home page Code Monkey logo

Comments (2)

amwx avatar amwx commented on September 18, 2024

Don't store control instances in your ViewModels. Use the HeaderTemplate and ContentTemplate to control the view from a ViewModel:

 <ui:TabView IsAddTabButtonVisible="False"
             TabCloseRequested="TabView_TabCloseRequested"
             CanDragTabs="True" CanReorderTabs="True"
             TabItems="{Binding TabView}"
             SelectedItem="{Binding SelectedTab}">
     <ui:TabView.TabItemTemplate>
         <DataTemplate DataType="local:TabItem">
             <ui:TabViewItem IconSource="{Binding IconSource}"
                             Header="{Binding }"
                             Content="{Binding }">
                 <ui:TabViewItem.HeaderTemplate>
                     <DataTemplate DataType="local:TabItem">
                         <controls:MyCustomHeader />
                     </DataTemplate>
                 </ui:TabViewItem.HeaderTemplate>

                 <ui:TabViewItem.ContentTemplate>
                     <DataTemplate DataType="local:TabItem">
                         <controls:MyCustomContent />
                     </DataTemplate>
                 </ui:TabViewItem.ContentTemplate>
             </ui:TabViewItem>
         </DataTemplate>
     </ui:TabView.TabItemTemplate>
 </ui:TabView>

If you need more control over specific control views for each tab, then you need to wrap your headers and content ViewModels in their own classes and create DataTemplates for each. Read up and familiarize yourself with how MVVM works:

public class TabItemViewModel
{
    public TabItemHeaderBase Header { get; }
    public TabItemContentBase Content { get; }
}

// Base classes for TabItem headers and contents - derived classes can add extra functionality
public class TabItemHeaderBase
{
}

public class TabItemContentBase
{
}

Create DataTemplates to support each of these:

<Window.DataTemplates>
    <DataTemplate DataType="vm:TabItemHeader1">
         ....
    </DataTemplate>

    ...
</Window.DataTemplates>

Then just adjust your TabView like:

<ui:TabView IsAddTabButtonVisible="False"
            TabCloseRequested="TabView_TabCloseRequested"
            CanDragTabs="True" CanReorderTabs="True"
            TabItems="{Binding TabView}"
            SelectedItem="{Binding SelectedTab}">
    <ui:TabView.TabItemTemplate>
        <DataTemplate DataType="local:TabItem">
            <ui:TabViewItem IconSource="{Binding IconSource}"
                            Header="{Binding Header}"
                            Content="{Binding Content}">
            </ui:TabViewItem>
        </DataTemplate>
    </ui:TabView.TabItemTemplate>
</ui:TabView>

from fluentavalonia.

rasta-mouse avatar rasta-mouse commented on September 18, 2024

Ahhh, yes I understand. I see now that my question was pretty stupid 😥 Thanks for taking the time to provide such a detailed response.

from fluentavalonia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.