簡體   English   中英

通過點擊xamarin.forms列表中的圖像來聚焦時間選擇器

[英]Focus timepicker by tapping on image in a list in xamarin.forms

我有一個listview,由帶時間選擇器和圖像的堆棧布局組成。 我想要的是點擊時間選擇器應聚焦的圖像。 如果這些控件不在列表視圖中,則可以通過X:Name訪問它們,但是當它們在列表視圖中時如何聚焦。

首先,您需要創建一個自定義ViewCell

CustomCell.xaml

<ViewCell.View>
        <StackLayout>
            <Button Text="ImagTest" Clicked="Button_Clicked"/>
            <Picker x:Name="pickerTest"
        </StackLayout>
    </ViewCell.View>

然后,在CustomCell.xaml.cs中

public partial class CustomCell : ViewCell
    {
        public CustomCell ()
        {
            InitializeComponent ();
        }

        private void Button_Clicked(object sender, EventArgs e)
        {
            pickerTest.Focus();
        }
    }

在列表視圖頁面中定義名稱空間

 xmlns:local="clr-namespace:YourProject;assembly=YourProject"

在您的列表視圖中

<ListView HasUnevenRows="True" ItemSelected="ListView_ItemSelected" x:Name="listView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <local:CustomCell/>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM