我刚刚开发了我的第一个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)?
谢谢.
我的程序有一个按钮,当点击它打开一个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中没有选择图片时仍然会抛出异常.
我正在使用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)
另请注意,我有一CancellationTokenSource
对CancellationToken
。在用户点击取消按钮后,tokensource.Cancel()
被调用。此外,我的测试用例中的图像从 1 到 2 MB(不是那么大)。
那么,有没有办法取消HttpClient
POST 请求?
您好,我正在使用Xamarin.Forms,但我面临的是数据绑定问题ListView
。模型中有一个字符串值,模型中有一个列表,该列表是ItemsSource
ListView 的列表,字符串值应显示在每个单元格行中。
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) 有人可以给我一个理由,让我在一个推送通知通道上拥有一个registraiontId吗?目的是什么?
我已经阅读了很多有关处理推送通知的文章(我使用过Azure服务),但是我没有找到原因。我知道,频道会随着时间变化,然后我需要在后端的每个设备上更改我的注册ID上的频道。
以下方法似乎正在加载多个注册。为什么?
await HubClient.GetRegistrationsByChannelAsync("<pnsHandle>", 100)
Run Code Online (Sandbox Code Playgroud)
换句话说:渠道和注册之间的主要区别是什么?
我对此有些困惑...谢谢
c# ×4
xamarin ×2
cancellation ×1
events ×1
exception ×1
file-io ×1
http-post ×1
httpclient ×1
image ×1