Вы можете получить текущий элемент, добавив имя к:
<CarouselView x:Name="myCarouselView">
А затем получить текущий видимый стек:
private void Button_Clicked(object sender, EventArgs e)
{
ObservableCollection<View> views = myCarouselView.VisibleViews;
StackLayout st = views[0] as StackLayout;
st.Children.Clear();
//or
StackLayout st1 = myCarouselView.CurrentItem as StackLayout;
st1.Children.Clear();
}
Обновить :
добавить несколько макетов стека внутри карусели через c#
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
CarouselView carouselView = new CarouselView
{
ItemsLayout = (LinearItemsLayout)LinearItemsLayout.Horizontal
};
carouselView.ItemTemplate = new DataTemplate(typeof(CustomCell));
carouselView.ItemsSource = new string[]
{
"Baboon",
"Capuchin Monkey",
"Blue Monkey",
"Squirrel Monkey",
"Golden Lion Tamarin",
"Howler Monkey",
"Japanese Macaque"
};
Content = carouselView;
}
}
public class CustomCell : ContentView
{
public CustomCell()
{
//instantiate each of our views
var image = new Image();
StackLayout cellWrapper = new StackLayout();
StackLayout horizontalLayout = new StackLayout();
Label left = new Label();
Label right = new Label();
//set bindings
left.Text = "title";
right.Text = "title";
//Set properties for desired design
cellWrapper.BackgroundColor = Color.FromHex("#eee");
horizontalLayout.Orientation = StackOrientation.Horizontal;
right.HorizontalOptions = LayoutOptions.EndAndExpand;
left.TextColor = Color.FromHex("#f35e20");
right.TextColor = Color.FromHex("503026");
//add views to the view hierarchy
horizontalLayout.Children.Add(image);
horizontalLayout.Children.Add(left);
horizontalLayout.Children.Add(right);
cellWrapper.Children.Add(horizontalLayout);
this.Content = cellWrapper;
}
}