问题描述
我正在尝试使用 MediaElement 视图的参数“Duration”的值更改标签的参数“text”,它们都是同一个父项(Grid)的子项,并且该 Grid 位于集合视图。我想在单击框架(也是同一个 Grid 父级的子级)时更改参数文本。
<Grid
HeightRequest="145"
ColumnDeFinitions="25*,75*"
RowDeFinitions="21*,21*,24*,34*"
Padding="0"
RowSpacing="0">
<!--Only plays programmatically once,why? No idea-->
<xct:MediaElement
x:Name="mediaa"
Source="{Binding messageVoice}"
IsLooping="True"
KeepScreenOn="True"
Autoplay="False"
ShowsPlaybackControls="False"
HeightRequest="0"
WidthRequest="0"
Margin="0,0"
VerticalOptions="Center"
HorizontalOptions="Center"
Grid.Column="0"
Grid.Row="3">
</xct:MediaElement>
<Frame
x:Name="PlayFrame"
HasShadow="False"
CornerRadius="20"
BackgroundColor="Transparent"
HeightRequest="40"
WidthRequest="40"
IsClippedToBounds="True"
VerticalOptions="Start"
HorizontalOptions="Center"
Padding="0"
Grid.Column="1"
Grid.Row="3"
Margin="0,0">
<Image
Source="play.png"
Aspect="AspectFill"
HeightRequest="100">
</Image>
<Frame.GestureRecognizers>
<TapGestureRecognizer
Tapped="Play_Tapped">
</TapGestureRecognizer>
</Frame.GestureRecognizers>
</Frame>
<Label
Text="I want to change this property"
TextColor="Black"
FontAttributes="None"
FontSize="16"
Margin="15,0"
VerticalOptions="Start"
HorizontalOptions="Start"
Grid.Row="3"
Grid.Column="1">
</Label>
</Grid>
由于所有这些视图都位于 CollectionView 中,我无法使用它们的 x:names 访问它们,我能够从中提取信息的唯一方法是执行 TapGestureRecognizer 并访问这些视图的副本,但这样做我只能提取信息,不能改变它:
void Play_Tapped(System.Object sender,System.EventArgs e)
{
Frame frame = (Frame)sender;
Grid parent = (Grid)frame.Parent;
var audio = (MediaElement)parent.Children[0];
audio.Play();
//I should change the text property here,but I Couldn't do that since these views are just copies of the originals
}
我知道我可以将属性绑定到不同视图的属性,但是由于属性持续时间是 TimeSpan?属性,文本是字符串属性,我必须在更改文本值之前进行适当的转换。
感谢您抽出宝贵时间,如果您需要更多信息,我会在看到您的请求后立即提供给您。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)