Home > Enterprise >  How can control inside DataTemplate be found in Xamarin
How can control inside DataTemplate be found in Xamarin

Time:10-18

I have a control inside a DataTemplate. When that control executes the Tapped command I want it to be hidden without having to reload the ContentPage.

Page1.xaml

<StackLayout x:Name="sss" BindableLayout.ItemsSource="{Binding ....}">
    <BindableLayout.ItemTemplate>
        <DataTemplate>      
            <Frame x:Name="follower" IsVisible="{Binding Follow}">
                <Label Text="SSSS1" TextColor="#fff" FontSize="11"></Label>
                <Frame.GestureRecognizers>
                    <TapGestureRecognizer Tapped="follower_Tapped"/>
                </Frame.GestureRecognizers>
            </Frame>
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</StackLayout>

Page1.xaml.cs

FeedsViewModel feedsViewModel;
public Page1()
{
    BindingContext = feedsViewModel = new FeedsViewModel(Navigation);
    feedsViewModel.OnAppearing();
}

private void follower_Tapped(object sender, EventArgs e)
{
    string a = "s";
    //Find Control Frame x:Name="follower" to IsVisible False
    .......
}

How can I hide the Frame x:Name="follower" control when I follow_Tapped. Can anyone help me with a solution to this problem? Thank you

CodePudding user response:

You could set the IsVisible property in current Frame.

 private void follower_Tapped(object sender, EventArgs e)
    {
        var frame = sender as Frame;
        frame.IsVisible = false;
    }
  • Related