小编Art*_*nis的帖子

如何在xamarin中设置onclick监听器?

我对C#和Xamarin很陌生,并且一直试图实现底层元素并且不知道如何正确地执行它.我正在使用Cocosw.BottomSheet-Xamarin.Android库.

这是我的代码:

Cocosw.BottomSheetActions.BottomSheet.Builder b = new Cocosw.BottomSheetActions.BottomSheet.Builder (this);
b.Title ("New");
b.Sheet (Resource.Layout.menu_bottom_sheet)
Run Code Online (Sandbox Code Playgroud)

现在我认为我应该使用b.Listener(...),但它需要一个接口IDialogInterfaceOnClickListener作为参数,我不知道如何正确地在C#中做到这一点.

在Java中我可以写

button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Perform action on click
    }
});
Run Code Online (Sandbox Code Playgroud)

我试过这样做:

class BottomSheetActions : IDialogInterfaceOnClickListener {
    public void OnClick (IDialogInterface dialog, int which) {
        Console.WriteLine ("Hello fox");
    }

    public IntPtr Handle { get; }

    public void Dispose() {

    }
}
Run Code Online (Sandbox Code Playgroud)

然后这个:

b.Listener (new BottomSheetActions());
Run Code Online (Sandbox Code Playgroud)

但它没有用.

c# android xamarin.android xamarin

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

如何使用C#HttpClient PostAsync显示上传进度

我正在使用Xamarin PCL为Android和iOS创建文件上传应用程序,我已设法实现文件上传和某种进度条,但它无法正常工作.

我看到堆栈溢出的一些答案用于显示下载进度,但我想通知我的用户有关上传进度的信息,但没有找到任何解决方案.

这是我的代码:

public static async Task<string> PostFileAsync (Stream filestream, string filename, int filesize) {
        var progress = new System.Net.Http.Handlers.ProgressMessageHandler ();

        //Progress tracking
        progress.HttpSendProgress += (object sender, System.Net.Http.Handlers.HttpProgressEventArgs e) => {
            int progressPercentage = (int)(e.BytesTransferred*100/filesize);
            //Raise an event that is used to update the UI
            UploadProgressMade(sender, new System.Net.Http.Handlers.HttpProgressEventArgs(progressPercentage, null, e.BytesTransferred, null));
        };

        using (var client = HttpClientFactory.Create(progress)) {
            using (var content = new MultipartFormDataContent ("------" + DateTime.Now.Ticks.ToString ("x"))) {
                content.Add (new StreamContent (filestream), "Filedata", filename);
                using (var …
Run Code Online (Sandbox Code Playgroud)

c# file-upload progress httpclient xamarin

6
推荐指数
3
解决办法
9306
查看次数