当我尝试在Visual Studio上运行该应用程序时,我遇到了一个例外。我正在尝试使用xamarin表单构建时间表,当有人单击相关性(“ Prioridade”的4个选项)时,它将时间表作为新事件保存。每当我尝试在仿真中尝试新的事情时,都会遇到相同的错误。以下是代码:
XAML
> new Date(new Date().setHours(0, 0, 0, 0))
2019-12-03T23:00:00.000Z
我遇到了大多数问题的C#
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns ="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XPerfilEMenu.Tarefas.Cadastro">
<ContentPage.Content>
<StackLayout Margin="40" Spacing="40">
<Label FontAttributes="Bold" Text="Nome da tarefa" />
<Entry x:Name="TarefaDigitada"/>
<Label FontAttributes="Bold" Text="Prioridade da tarefa" />
<StackLayout x:Name="SLPrioridades" Spacing="30">
<!--URGENTE E IMPORTANTE-->
<StackLayout Spacing="10" Orientation="Horizontal">
<!--<Image Source="4.png"/>-->
<Image>
<Image.Source>
<OnPlatform
x:TypeArguments="FileImageSource">
<On
Platform="iOS, Android"
Value="Vermelho.png" />
</OnPlatform>
</Image.Source>
</Image>
<Label
Text="Urgente e importante"
TextColor="Gray"
HorizontalOptions="FillAndExpand" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="PrioridadeEscolhida" />
</StackLayout.GestureRecognizers>
</StackLayout>
<!--URGENTE E NÃO IMPORTANTE-->
<StackLayout
Spacing="10"
Orientation="Horizontal">
<Image
Source="Laranja.png" />
<Label
Text="Urgente e não importante"
HorizontalOptions="FillAndExpand"
TextColor="Gray" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="PrioridadeEscolhida" />
</StackLayout.GestureRecognizers>
</StackLayout>
<!--NÃO URGENTE E IMPORTANTE-->
<StackLayout
Spacing="10"
Orientation="Horizontal">
<Image
Source="Amarelo.png" />
<Label
Text="Não urgente e importante"
HorizontalOptions="FillAndExpand"
TextColor="Gray" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="PrioridadeEscolhida" />
</StackLayout.GestureRecognizers>
</StackLayout>
<!--NÃO URGENTE E NÃO IMPORTANTE-->
<StackLayout
Spacing="10"
Orientation="Horizontal">
<Image
Source="Verde.png" />
<Label
Text="Não urgente e não importante"
HorizontalOptions="FillAndExpand"
TextColor="Gray" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="PrioridadeEscolhida" />
</StackLayout.GestureRecognizers>
</StackLayout>
<!-- ADICIONAR BOTÃO -->
<Button HorizontalOptions="End" Margin="20" Clicked="AdicionarTarefa">
<Button.ImageSource>
<OnPlatform
x:TypeArguments="FileImageSource">
<On
Platform="iOS, Android"
Value="AddBotao.png" />
</OnPlatform>
</Button.ImageSource>
</Button>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
答案 0 :(得分:0)
为什么要遍历布局,这很繁琐且容易出错。
您可以使用属性:x:Name
:例如:
<Label
x:Name="LabelPrioridade"
Text="Urgente e não importante"
HorizontalOptions="FillAndExpand"
TextColor="Gray" />
像这样使用,非常简单:
LabelPrioridade.TextColor = Color.Gray;