我正在开发跨平台xamarin应用程序,我想为"忘记密码?"创建超链接标签.在登录页面上.我使用以下代码来创建标签,但我不知道如何在其上创建onclick事件.
MainPage = new ContentPage
{
BackgroundImage = "background.png",
Content = new StackLayout
{
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Spacing = 50,
Children = {
new Label {
HorizontalTextAlignment = TextAlignment.Center,
Text = "Welcome, Please Sign in!",
FontSize=50,
TextColor=Color.Gray,
},
new Entry
{
Placeholder="Username",
VerticalOptions = LayoutOptions.Center,
Keyboard = Keyboard.Text,
HorizontalOptions = LayoutOptions.Center,
WidthRequest = 350,
HeightRequest = 50,
FontSize=20,
TextColor=Color.Gray,
PlaceholderColor=Color.Gray,
},
new Entry
{
Placeholder="Password",
VerticalOptions = LayoutOptions.Center,
Keyboard = Keyboard.Text,
HorizontalOptions = LayoutOptions.Center,
WidthRequest = 350, …Run Code Online (Sandbox Code Playgroud) 我在Xamarin.Forms中创建了一个新项目并调试它.我什么都不做,只是创建一个Apk文件,apk大小是14.2 MB.我找到了一些关于Linker行为的教程并将其更改为链接所有程序集.它将Apk大小减少到1或2 MB.事实上,我预计这种Apk的大小应该在一些kbs中.我在这里缺少什么?
我在 Dto 后面添加了一些属性来验证属性。当我传递一些无效的属性值时,我的单元测试允许这些值,而不根据给定的属性条件进行验证。我是第一次这样做,所以我对实现它的想法为零。
\n\npublic class UserDto : IModelWithId\n{\n public int Id { get; set; }\n [MinLength(1, ErrorMessageResourceName = "Error_User_UsernameMinLength", ErrorMessageResourceType = typeof(Properties.Resources))]\n [MaxLength(255, ErrorMessageResourceName = "Error_User_UsernameMaxLength", ErrorMessageResourceType = typeof(Properties.Resources))]\n [RegularExpression(@"^[A-Za-z0-9\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f]+(?:[._-][A-Za-z0-9\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f]+)*$", ErrorMessageResourceName = "Error_User_UsernameFormat", ErrorMessageResourceType = typeof(Properties.Resources))]\n public string UserName { get; set; } \n\n [MinLength(1, ErrorMessageResourceName = "Error_User_NameMinLength", ErrorMessageResourceType = typeof(Properties.Resources))]\n [MaxLength(255, ErrorMessageResourceName = "Error_User_NameMaxLength", ErrorMessageResourceType = typeof(Properties.Resources))]\n public string Name { get; set; }\n\n [MinLength(1, ErrorMessageResourceName = "Error_User_EmailMinLength", ErrorMessageResourceType = typeof(Properties.Resources))]\n [MaxLength(255, ErrorMessageResourceName = "Error_User_EmailMaxLength", ErrorMessageResourceType = typeof(Properties.Resources))]\n …Run Code Online (Sandbox Code Playgroud) 我想从数组中找出第k个最常见的元素,我能够找到最常见的元素,但我不知道如何找到第k个常见元素.
我尝试过:
private static int KthCommonElement(int[] a, int k)
{
var counts = new Dictionary<int, int>();
foreach (int number in a)
{
int count;
counts.TryGetValue(number, out count);
count++;
//Automatically replaces the entry if it exists;
//no need to use 'Contains'
counts[number] = count;
}
int mostCommonNumber = 0, occurrences = 0;
foreach (var pair in counts)
{
if (pair.Value > occurrences)
{
occurrences = pair.Value;
mostCommonNumber = pair.Key;
}
}
Console.WriteLine("The most common number is {0} and it appears {1} …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个扫描仪,当我扫描任何QR码时,我需要获得纬度 - 经度的设备的当前位置.我不知道如何获取位置,所以我现在没有任何代码.建议我一些方法来获取扫描完成QR码的位置.
我正在使用Xamarin Studio在Mac机器上使用PCL创建我的第一个xamarin表单应用程序.我阅读了很多文章来创建应用程序的全局样式,但是我无法访问在App.xaml.cs文件中声明的应用程序内部任何文件的样式.我在下面提到我使用的代码.或者,如果有人有其他选择让它变得容易或无论如何可能请建议我.提前致谢.
App.xaml.cs-
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="DinePerfect.App">
<Application.Resources>
<ResourceDictionary>
<Style x:Key="btnStyle" TargetType="Button">
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="CenterAndExpand" />
<Setter Property="BorderColor" Value="Lime" />
<Setter Property="BorderRadius" Value="5" />
<Setter Property="BorderWidth" Value="5" />
<Setter Property="WidthRequest" Value="200" />
<Setter Property="TextColor" Value="Teal" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)
在其他文件中调用样式 -
<Button Text="Login" Style="{StaticResource btnStyle} TextColor="Black" BackgroundColor="#9C661F" Clicked="btnLoginClicked" />
Run Code Online (Sandbox Code Playgroud) 我有这样的Dto:
public class OptimizationNodeDto : IModelWithId
{
public int Id { get; set; }
[DataMember(Name = "parentId")]
public int? ParentOptimizationNodeId { get; set; }
[DataMember(Name = "name")]
public string Text { get; set; }
[DataMember(Name = "opened")]
public bool IsOpened { get; set; }
[DataMember(Name = "selected")]
public SelectedStates SelectedState { get; set; }
public List<OptimizationNodeDto> Children { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我希望当我使用任何 API 发送这个对象时,它应该像 DataMember 中提到的那样在 JSON 中给出属性名称,但它没有发生。对于 ex.ParentOptimizationNodeId 应该作为 JSON 结果中的 parentId。我在这里发送 Dto:
[Route("{roleId}/Optimizations")]
[HttpPost]
public IHttpActionResult GetOptimizationList([FromUri]int …Run Code Online (Sandbox Code Playgroud) 我已经使用 Xamarin Studio 创建了我的第一个 Xamarin.Forms 应用程序。我的应用程序无法记住默认用户名,因此用户每次都必须登录应用程序,这很烦人。如果他/她尚未从应用程序注销,我如何存储最后一个用户凭据以自动登录?在PCL中可能吗?
c# ×6
android ×1
arrays ×1
asp.net-mvc ×1
attributes ×1
autologin ×1
location ×1
mocking ×1
search ×1
styles ×1
unit-testing ×1
xamarin ×1
xaml ×1