我有一个GridView,每个磁贴包含用户特定的详细信息,因此如果用户的详细信息在使用应用程序时必须更改,我希望刷新此视图 . 我已经尝试了以下方法,为我的一个瓷砖添加刷新,但这不起作用 . 有没有其他方法可以实现整个gridView?
Xaml
<Grid x:Name="cardBalance" >
<Image Source="GiftCard.jpg" HorizontalOptions="Fill" VerticalOptions="Fill" Aspect="AspectFill" Grid.Row="0" Grid.Column="0" x:Name="CardImage"/>
<Image Source="store2.jpg" HorizontalOptions="Fill" VerticalOptions="Fill" Aspect="AspectFill" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"/>
<Image Source="GridTrans.jpg" HorizontalOptions="Fill" VerticalOptions="Fill" Aspect="AspectFill" Grid.Row="0" Grid.Column="1" />
<Image Source="ProfileBg2.JPG" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill" Grid.Row="2" Grid.Column="0" />
<Image Source="gridSettings.JPG" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill" Grid.Row="2" Grid.Column="1" />
<ScrollView Grid.Row="0" Grid.Column="0">
<ListView x:Name="CardBalance" HasUnevenRows="True" Grid.Row="0" Grid.Column="0" VerticalOptions="Fill" IsPullToRefreshEnabled="True" Refreshing="CardBalance_Refreshing">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
x:Name="Layout">
<Frame>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
<Label Text="Card Balance:" TextColor="Black"/>
<Label Text="{Binding Balance}" TextColor="Black"/>
</StackLayout>
<StackLayout Orientation="Vertical" HorizontalOptions="EndAndExpand">
<Image Source="{Binding CustomerLogo}" HeightRequest="60" WidthRequest="60"></Image>
</StackLayout>
</StackLayout>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
<Label Text=" Tap to view detail" TextColor="Gainsboro" FontSize="14" FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="End" Grid.Row="0" Grid.Column="0" x:Name="CardTile"/>
<Label Text=" Tap to view all card balances" TextColor="#64676b" FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="End" Grid.Row="0" Grid.Column="0" x:Name="MultipleCards"/>
<Label Text=" Transactions" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="End" Grid.Row="0" Grid.Column="1" x:Name="TransactionTile"/>
<Label Text=" Promotions" TextColor="White" FontSize="30" FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="End" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="PromoTile"/>
<Label Text=" My Profile" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="End" Grid.Row="2" Grid.Column="0" x:Name="ProfileTile" />
<Label Text=" Settings" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="End" Grid.Row="2" Grid.Column="1" x:Name="SettingsTile"/>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
</Grid>
Xaml.cs
public async void LoadCards()
{
try
{
List<Requests.Cards> cd = new List<Requests.Cards>();
var content = "";
HttpClient client = new HttpClient();
var RestUrl = Settings.RestUrl + "/api/Customer/GetCustomerCards?CustomerID=" + Helpers.Settings.storecustID;
client.BaseAddress = new Uri(RestUrl);
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-Giftworx-App", Helpers.Settings.Usertoken);
HttpResponseMessage response = await client.GetAsync(RestUrl);
content = await response.Content.ReadAsStringAsync();
var Items = JsonConvert.DeserializeObject<List<Requests.Cards>>(content);
CardBalance.ItemsSource = Items;
TapGestureRecognizer cardsLabel = new TapGestureRecognizer();
cardsLabel.Tapped += (sender, e) =>
{
Navigation.PushAsync(new Cards());
};
CardTile.GestureRecognizers.Add(cardsLabel);
}
catch (Exception ex)
{
string exception = ex.Message;
}
}
private void CardBalance_Refreshing(object sender, EventArgs e)
{
LoadCards();
CardBalance.IsRefreshing = false;
}