[英]xamarin forms capture listview from button click
My code below displays a listview, when button 'Please play your order' is clicked, the function ButtonPressed(object sender, EventArgs e) is hit.我下面的代码显示了一个列表视图,当单击“请播放您的订单”按钮时,function ButtonPressed(object sender, EventArgs e) 被击中。 How can I capture the entire listview from the ButtonPressed function...如何从 ButtonPressed function 捕获整个列表视图...
I have tried something like我试过类似的东西
void ButtonPressed(object sender, EventArgs e)
{
var listView = (ListView)sender;//but this did not work
}
<ContentPage.Content>
<StackLayout>
<ListView ItemsSource="{Binding CompletedList}" HasUnevenRows="True" SeparatorVisibility="None">
<ListView.Header>
<Button Text="Please place your order" Clicked="ButtonPressed"/>
</ListView.Header>
<ListView.Footer>
<Label x:Name="Items" HorizontalTextAlignment="End" VerticalTextAlignment="Start" Margin="20,20" FontAttributes="Bold"/>
</ListView.Footer>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10" RowSpacing="10" ColumnSpacing="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="{Binding I_D}" VerticalOptions="End" IsVisible="False"/>
<Label Grid.Column="2" Grid.Row="1" Text="{Binding NameOfProduct}" VerticalOptions="End"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
your ListView
is bound to CompletedList
, so you really just need to access that variable, not the ListView
itself.您的ListView
绑定到CompletedList
,因此您实际上只需要访问该变量,而不是ListView
本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.