【发布时间】:2019-06-21 20:35:24
【问题描述】:
我有一个图像按钮,当我单击该按钮时,我想更改其评分的来源(一个空星为实心星)。
我的 XAML:
<StackLayout Grid.Row="1" Orientation="Horizontal" Spacing="0">
<ImageButton Source="star_empty.png"
HeightRequest="40"
WidthRequest="40"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
x:Name="star1"
BackgroundColor="Transparent"
Clicked="ImageButton_Clicked" />
<ImageButton Source="star_empty.png"
HeightRequest="40"
WidthRequest="40"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
x:Name="star2"
BackgroundColor="Transparent"
Clicked="ImageButton_Clicked2" />
<ImageButton Source="star_empty.png"
HeightRequest="40"
WidthRequest="40"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
x:Name="star3"
BackgroundColor="Transparent"
Clicked="ImageButton_Clicked3" />
<ImageButton Source="star_empty.png"
HeightRequest="40"
WidthRequest="40"
x:Name="star4"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
BackgroundColor="Transparent"
Clicked="ImageButton_Clicked4" />
<ImageButton Source="star_empty.png"
HeightRequest="40"
WidthRequest="40"
x:Name="star5"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
BackgroundColor="Transparent"
Clicked="ImageButton_Clicked5" />
</StackLayout>
视图类:
private void ImageButton_Clicked(object sender, EventArgs e)
{
star1.Source = "star_full.png";
int rating = 1;
}
可能是什么问题?源头确实发生了变化,它只是闪烁然后消失。我将 isVisible 属性设置为 true,这没有帮助。
【问题讨论】:
标签: xaml xamarin xamarin.forms imagebutton