首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在listview - xamarin窗体的项中引用控件或视图

问如何在listview - xamarin窗体的项中引用控件或视图
EN

Stack Overflow用户
提问于 2017-05-17 19:48:25
回答 1查看 322关注 0票数 0

我有这样一个场景,在ListView中,我有两个标签,每个项目都有一个自定义的水平列表。

水平列表-在ScrollView中以水平方向堆叠标签。

我需要的是,我想引用一个标签,这是内的ListView的一个特定项目的水平列表,并使选定的标签从水平列表到粗体。有没有办法引用ListView项的控件?

下面是用于填充我的ListView的代码

代码语言:javascript
复制
myListView = new ListView
{
    // Source of data items.
    ItemsSource = itemsource,
    HasUnevenRows = true,
    RowHeight = -1,

    ItemTemplate = new DataTemplate(() =>
    {
        Label label1 = new Label()
        {
            TextColor = Color.Black,
            HorizontalTextAlignment = TextAlignment.Start,
            FontSize = Device.GetNamedSize(NamedSize.Small, new Label())
        };
        label1.SetBinding<LVItem>(Label.TextProperty, indexer => indexer.Name);

        Label label2 = new Label()
        {
            TextColor = Color.Black,
            HorizontalTextAlignment = TextAlignment.Start,
            FontSize = Device.GetNamedSize(NamedSize.Small, new Label())
        };
        label2.SetBinding<LVItem>(Label.TextProperty, indexer => indexer.SelectedNum);

    //horizontal list
        StackLayout sLayout = new StackLayout()
        {
            Orientation = StackOrientation.Horizontal,
        };

        for (int i = 0; i<itemLst.Count; i++)
        {
            Label label3 = new Label()
            {
                HorizontalTextAlignment = TextAlignment.Center,
                TextColor = Color.Black,
                FontSize = Device.GetNamedSize(NamedSize.Medium, new Label())
            };
            label3.Text = itemLst[i];

            gestureRecognizer = new TapGestureRecognizer
            {
                Command = new Command(TapL_Tapped),
                CommandParameter = label3,
            };

            label3.GestureRecognizers.Add(gestureRecognizer);

            sLayout.Children.Add(label3);
        }

        ScrollView scroll = new ScrollView
        {
            Orientation = ScrollOrientation.Horizontal,
            Content = new StackLayout
            {
                Children =
                {
                    sLayout
                }
            }
        };


        AbsoluteLayout layout = new AbsoluteLayout();
        AbsoluteLayout.SetLayoutFlags(label1, AbsoluteLayoutFlags.All);
        AbsoluteLayout.SetLayoutBounds(label1, new Rectangle(0.2, 0.2, 0.8, 0.25));

        AbsoluteLayout.SetLayoutFlags(scroll, AbsoluteLayoutFlags.All);
        AbsoluteLayout.SetLayoutBounds(scroll, new Rectangle(0.3, 0.6, 0.8, 0.2));

        AbsoluteLayout.SetLayoutFlags(label2, AbsoluteLayoutFlags.All);
        AbsoluteLayout.SetLayoutBounds(label2, new Rectangle(1.1, 0.3, 0.5, 0.2));

        layout.Children.Add(label1);
        layout.Children.Add(scroll);
        layout.Children.Add(label2);

        return new ViewCell
        {
            View = new StackLayout
            {
                Children =
                {
                    layout,
                }
            }
        };
    }
)};
EN

回答 1

Stack Overflow用户

发布于 2017-05-19 21:47:22

您可以使用ItemTapped来查找列表视图中的哪个项目正在被点击。要使文本加粗,您应该在字体上使用绑定。然后在你的代码幕后,你可以切换绑定的值,你的字体也会改变。让我知道这是否对你有效!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44024001

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档