Xamarin,获取呼叫时间,然后将其显示在 XAML 页面中



我正在尝试在我的页面中添加一段代码来获取通话时间。在 XAML 代码中,我有一个显示人员列表的列表视图和一个按姓名查找的搜索栏,我还有一个可单击的标签来调用定义的号码。我只是想找到一种方法来显示通话后的时间。我只需要知道如何使它成为可能。如果有必要,我可以描述更多我的代码。我的尝试没有成功。

要调用的代码:

var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) =>
{
Device.OpenUri(new Uri("phone:00000000"));
};

Number.GestureRecognizers.Add(tapGestureRecognizer);

XAML :

<ContentPage.Content>

<StackLayout>
<Label Text="People"
HorizontalOptions="CenterAndExpand" />
<ListView x:Name="lstView" BackgroundColor="Beige" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding .}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

<Label x:Name="Number" HorizontalOptions="Center">Call</Label>
<SearchBar x:Name="searchBar"  Placeholder="search" SearchButtonPressed="OnSearchBarButtonPressed" 
Text="{Binding SearchedText, Mode=TwoWay}"
SearchCommand="{Binding SearchCommand}"/>
<Label x:Name="searchResults" HorizontalOptions="Center" />
</StackLayout>
</ContentPage.Content>

将 DateTime 属性添加到 Person 对象:

public class Person
{
public DateTime DateTime { get; set; }
}

在视图模型中分配一个值:

public ObservableCollection<Person> People { get; set; } = new 
ObservableCollection<Person>();
var p = new Person();
p.DateTime = DateTime.Now
People.Add(p);

并将其绑定到您的 xaml 中:

<StackLayout Grid.Column="2" VerticalOptions="Center" 
HorizontalOptions="Center">
<Label Text="{Binding DateTime}" HorizontalOptions="Center"/>
</StackLayout>

最新更新