小编Joe*_*ehl的帖子

xamarin.forms中的页面生命周期事件

我刚刚开发了我的第一个xamarin.forms应用程序.我对xamarin.forms很兴奋,但我想念几个事件.

在xamarin.forms ContentPage中是否有任何页面生命周期事件?

我知道这两个:

protected override void OnAppearing()
{
}

protected override void OnDisappearing()
{
}
Run Code Online (Sandbox Code Playgroud)

但OnAppearing()事件只触发一次.在Android上,当我按下开始按钮并返回到我的应用程序时,此事件不会再次触发.

是否有解决方法(如WindowsPhone页面中的OnNavigatedTo)?

谢谢.

c# events page-lifecycle xamarin xamarin.forms

27
推荐指数
3
解决办法
4万
查看次数

取消openfiledialog时如何防止异常?

我的程序有一个按钮,当点击它打开一个openfiledialog来选择一张图片:

private string ChoosePicture()
{         
    fDialog.Title = "Select Picture";
    fDialog.Filter = "Image Files (*.bmp, *.gif, *.jpg)|*.bmp; *.gif*;*.jpg";
    fDialog.InitialDirectory = "C:";
    fDialog.ShowDialog();

    fDialog.AddExtension = true;
    fDialog.CheckFileExists = true;
    fDialog.CheckPathExists = true;

    //returns a string for the directory
    return fDialog.FileName.ToString();
}
Run Code Online (Sandbox Code Playgroud)

使用dialogresult框上的检查还没有解决我的问题:

fDialog.AddExtension = true;
fDialog.CheckFileExists = true;
fDialog.CheckPathExists = true;

DialogResult res = fDialog.ShowDialog();
if (res == DialogResult.OK)
{                
    //returns a string for the directory
    return fDialog.FileName.ToString();
}

return null; 
Run Code Online (Sandbox Code Playgroud)

如果我选择图片并完成文件选择,代码可以正常工作.但是,如果我在两者之间的任何时候取消该过程,我会得到例外情况"路径不是合法形式".我不确定哪个部分我想象我可以用a来处理这个问题try-catch,但是我不肯定哪个部分导致了这个问题?如果我try catch调用ChoosePicture()方法,我至少可以阻止它崩溃程序,但是当fdialogbox中没有选择图片时仍然会抛出异常.

c# file-io image exception openfiledialog

8
推荐指数
1
解决办法
2万
查看次数

取消“HttpClient”POST 请求

我正在使用HttpClient.PostAsync()我的 Windows Phone 8 应用上传图像。用户可以选择通过 UI 按钮取消此上传。

为了取消 POST 请求,我设置了一个CancellationToken. 但这不起作用。在取消请求之后,我仍然看到在我的代理中进行了上传,很明显该请求被忽略了。我的代码:

using (var content = new MultipartFormDataContent())
{
    var file = new StreamContent(stream);
    file .Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
    {
        FileName =  "filename.jpg",
    };
    file.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
    content.Add(file);

    await httpclient.PostAsync(new Uri("myurl", UriKind.Absolute), content,
        cancellationToken);
}
Run Code Online (Sandbox Code Playgroud)

另请注意,我有一CancellationTokenSourceCancellationToken。在用户点击取消按钮后,tokensource.Cancel()被调用。此外,我的测试用例中的图像从 1 到 2 MB(不是那么大)。

那么,有没有办法取消HttpClientPOST 请求?

c# httpclient http-post cancellation windows-phone-8

5
推荐指数
1
解决办法
5282
查看次数

以xamarin形式绑定来自listView的Itemsource外部的数据

您好,我正在使用Xamarin.Forms,但我面临的是数据绑定问题ListView。模型中有一个字符串值,模型中有一个列表,该列表是ItemsSourceListView 的列表,字符串值应显示在每个单元格行中。

XMAL视图

<ListView ItemsSource="{Binding StudentList, Mode=TwoWay}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout>
                    <Label Text={Binding Name} />
                    <Label Text={Binding ConstantName} /> //// Not present in Itemsource. Should bind from Model. It does not render.
                 </Stacklayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)

C#

public ObservableCollection<PagingButtons> _lstPagingButtons { get; set; }
public ObservableCollection<PagingButtons> lstPagingButtons
{
    get { return _lstPagingButtons; }
    set
    {
        _lstPagingButtons = value;
        OnPropertyChanged();
    }
}
string _ConstantName {get; set;} = "Xamarin";
public string ConstantName 
{
    get { return _ConstantName; …
Run Code Online (Sandbox Code Playgroud)

xamarin xamarin.forms

3
推荐指数
1
解决办法
501
查看次数

一个通道的多个推送注册

有人可以给我一个理由,让我在一个推送通知通道上拥有一个registraiontId吗?目的是什么?

我已经阅读了很多有关处理推送通知的文章(我使用过Azure服务),但是我没有找到原因。我知道,频道会随着时间变化,然后我需要在后端的每个设备上更改我的注册ID上的频道。

以下方法似乎正在加载多个注册。为什么?

await HubClient.GetRegistrationsByChannelAsync("<pnsHandle>", 100)
Run Code Online (Sandbox Code Playgroud)

换句话说:渠道和注册之间的主要区别是什么?

我对此有些困惑...谢谢

c# push-notification azure-notificationhub

1
推荐指数
1
解决办法
571
查看次数