GithubHelp home page GithubHelp logo

syncfusionexamples / bring-child-node-to-view-treeview-xamarin Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 1.0 694 KB

This repository contains sample about how to bring the TreeView child node to view when the root node is collapsed in Xamarin.Forms (SfTreeView)

C# 100.00%
treeview sftreeview xamarin xamarin-forms

bring-child-node-to-view-treeview-xamarin's Introduction

How to bring the TreeView child node to view when the root node is collapsed in Xamarin.Forms (SfTreeView)

You can programmatically bring the child node to the view when all the root nodes are collapsed using BringIntoView method by expanding the particular root node in Xamarin.Forms SfTreeView.

You can also refer the following article.

https://www.syncfusion.com/kb/11802/how-to-bring-the-treeview-child-node-to-view-when-the-root-node-is-collapsed-in-xamarin

XAML

Use SfTreeView.NodePopulationMode property as Instant for SfTreeView.

<syncfusion:SfTreeView x:Name="treeView" ChildPropertyName="SubFiles" NodePopulationMode="Instant" ItemTemplateContextType="Node" ItemsSource="{Binding ImageNodeInfo}">
    <syncfusion:SfTreeView.ItemTemplate>
        <DataTemplate>
            <Grid x:Name="grid" RowSpacing="0" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="40" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Image Source="{Binding Content.ImageIcon}" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="35" WidthRequest="35"/>
                <Grid Grid.Column="1" RowSpacing="1" Padding="1,0,0,0" VerticalOptions="Center">
                    <Label LineBreakMode="NoWrap" Text="{Binding Content.ItemName}" VerticalTextAlignment="Center"/>
                </Grid>
            </Grid>
        </DataTemplate>
    </syncfusion:SfTreeView.ItemTemplate>
</syncfusion:SfTreeView>

C#

In the Button.Clicked event, bring any child item using BringIntoView method.

public class Behavior : Behavior<ContentPage>
{
    SfTreeView TreeView;
    Button Button;

    protected override void OnAttachedTo(ContentPage bindable)
    {
        TreeView = bindable.FindByName<SfTreeView>("treeView");
        Button = bindable.FindByName<Button>("button");
        Button.Clicked += Button_Clicked;
        base.OnAttachedTo(bindable);
    }

    private void Button_Clicked(object sender, EventArgs e)
    {
        var viewModel = (sender as SfTreeView).BindingContext as FileManagerViewModel;
        var item = viewModel.ImageNodeInfo[3].SubFiles[1];
        TreeView.BringIntoView(item, true, true);
        TreeView.SelectedItem = item;
    }
}

Output

TreeViewBringToView

bring-child-node-to-view-treeview-xamarin's People

Contributors

jayaleshwari avatar lakshminatarajan avatar sarubala20 avatar syncfusionbuild avatar

Watchers

 avatar  avatar  avatar  avatar

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.