C# 在Xamarin.Forms上的Salve计划作业
当我尝试在visual studio上运行应用程序时,出现了一个异常问题。我试图用xamarin表单建立一个时间表,当有人点击相关性(“Prioridade”的4个选项)时,它作为一个新的事件在时间表上得到了补救。每次我试图在模拟上做一件新的事情,我都会犯同样的错误。代码如下: XAMLC# 在Xamarin.Forms上的Salve计划作业,c#,xamarin,xamarin.forms,schedule,C#,Xamarin,Xamarin.forms,Schedule,当我尝试在visual studio上运行应用程序时,出现了一个异常问题。我试图用xamarin表单建立一个时间表,当有人点击相关性(“Prioridade”的4个选项)时,它作为一个新的事件在时间表上得到了补救。每次我试图在模拟上做一件新的事情,我都会犯同样的错误。代码如下: XAML <?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns ="http://xamarin.com/schemas/2
<?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>
为什么要遍历布局,它相当乏味而且容易出错 您可以使用属性:
x:Name
:例如:
<Label
x:Name="LabelPrioridade"
Text="Urgente e não importante"
HorizontalOptions="FillAndExpand"
TextColor="Gray" />
为什么要遍历布局,它相当乏味而且容易出错 您可以使用属性:
x:Name
:例如:
<Label
x:Name="LabelPrioridade"
Text="Urgente e não importante"
HorizontalOptions="FillAndExpand"
TextColor="Gray" />
“我也犯了同样的错误。”错误是什么?请发布您收到的错误/异常。System.InvalidCastException foi gerado Speciefied cast无效,并选择以下行:Label LabelPrioridade=((StackLayout)Linha).Children[1]作为标签;“我也犯了同样的错误。”错误是什么?请发布您收到的错误/异常。System.InvalidCastException foi gerado Speciefied cast无效,并选择以下行:Label LabelPrioridade=((StackLayout)Linha).Children[1]作为标签;
LabelPrioridade.TextColor = Color.Gray;