我的.NET MAUI应用在编写了一对绑定行后无法打开。

huangapple go评论106阅读模式
英文:

My app in .net maui isnt openning after write a pair of binding lines

问题

这是你的翻译好的部分:

首先,对不起我的英语。我正在创建一个视图以创建一个新的元素。该元素具有一些常见属性和一些取决于我们在单选按钮中选择的子项的属性。如果选中值为"Serie"的单选按钮,我希望只看到堆栈1(来自系列);如果选中值为"Pelicula"的单选按钮,我希望看到堆栈2(来自电影),依此类推。以下是最后一个可工作的代码:

我在网格的Grid.Column=1内的StackLayout中添加了一些绑定,但它停止工作了。它没有报错,但窗口应用程序甚至没有打开。

请注意,我已将双引号转义为单引号,以适应HTML/XML的格式。

英文:

(first of all, sorry for my english). Im making a view to make a new element. the element have some common attributes and some that depends on the child we choose in the radiobutton. i want to se only the stack 1(from series) if the radio button with Value="Serie" is checked, the stack 2(from movies) if the radio button with Value="Pelicula" is checked and so on. here is the last working code:

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  4. xmlns:local="clr-namespace:GameVidNet"
  5. x:Class="GameVidNet.Paginas.NewMediaPage"
  6. Title="NewMediaPage">
  7. <Grid>
  8. <Grid.ColumnDefinitions>
  9. <ColumnDefinition Width="*" />
  10. <ColumnDefinition Width="*" />
  11. </Grid.ColumnDefinitions>
  12. <StackLayout Padding="20" VerticalOptions="Center" HorizontalOptions="Center" Grid.Column="0" >
  13. <Label Text="Tipo de Media" FontSize="16" />
  14. <HorizontalStackLayout>
  15. <RadioButton Value="Serie" Margin="20" >
  16. <RadioButton.Content>
  17. <Image Source="series.png" HeightRequest="30" WidthRequest="30"/>
  18. </RadioButton.Content>
  19. </RadioButton>
  20. <RadioButton Value="Pelicula" Margin="20" >
  21. <RadioButton.Content>
  22. <Image Source="movie.png" HeightRequest="30" WidthRequest="30"/>
  23. </RadioButton.Content>
  24. </RadioButton>
  25. <RadioButton Value="Videojuego" Margin="20" >
  26. <RadioButton.Content>
  27. <Image Source="videogame.png" HeightRequest="30" WidthRequest="30"/>
  28. </RadioButton.Content>
  29. </RadioButton>
  30. </HorizontalStackLayout>
  31. <Label Text="ID" FontSize="16" />
  32. <Entry x:Name="IdEntry" Placeholder="Ingrese el ID" />
  33. <Label Text="Título" FontSize="16" />
  34. <Entry x:Name="TitleEntry" Placeholder="Ingrese el título" />
  35. <Label Text="Género" FontSize="16" />
  36. <Entry x:Name="GenreEntry" Placeholder="Ingrese el género" />
  37. <Label Text="Año de Lanzamiento" FontSize="16" />
  38. <Entry x:Name="ReleaseYearEntry" Placeholder="Ingrese el año de lanzamiento" />
  39. <Button Text="Guardar" Clicked="SaveButton_Clicked" Margin="0,20,0,0" />
  40. </StackLayout>
  41. <StackLayout Grid.Column="1" Padding="20" VerticalOptions="Center" HorizontalOptions="Center">
  42. <StackLayout >
  43. <Label Text="Temporadas" FontSize="16" />
  44. <Entry x:Name="SeasonsEntry" Placeholder="Ingrese el número de temporadas" />
  45. <Label Text="Duración promedio del episodio" FontSize="16" />
  46. <Entry x:Name="AverageEpisodeDurationEntry" Placeholder="Ingrese la duración promedio del episodio" />
  47. <Label Text="Es Anime" FontSize="16" />
  48. <Switch x:Name="IsAnimeSwitch" />
  49. <Label Text="Está completado" FontSize="16" />
  50. <Switch x:Name="IsCompletedSwitch" />
  51. </StackLayout>
  52. <StackLayout >
  53. <Label Text="Duración" FontSize="16" />
  54. <Entry x:Name="DurationEntry" Placeholder="Ingrese la duración" />
  55. <Label Text="Edad recomendada" FontSize="16" />
  56. <Entry x:Name="RecommendedAgeEntry" Placeholder="Ingrese la edad recomendada" />
  57. <Label Text="Ganador de premios" FontSize="16" />
  58. <Switch x:Name="AwardWinnerSwitch" />
  59. </StackLayout>
  60. <StackLayout >
  61. <Label Text="Plataformas" FontSize="16" />
  62. <Entry x:Name="PlatformsEntry" Placeholder="Ingrese las plataformas" />
  63. <Label Text="Modos de juego" FontSize="16" />
  64. <Entry x:Name="GameModesEntry" Placeholder="Ingrese los modos de juego" />
  65. <Label Text="Es original" FontSize="16" />
  66. <Switch x:Name="IsOriginalSwitch" />
  67. <Label Text="Está inspirado" FontSize="16" />
  68. <Switch x:Name="IsInspiredSwitch" />
  69. </StackLayout>
  70. </StackLayout>
  71. </Grid>
  72. </ContentPage>

i put some bindings in the stackslayout inside the stacklayout grid.column=1, and it stops working. it doesnt give me any errors but the window app is not even opening.

  1. <StackLayout Grid.Column="1" Padding="20" VerticalOptions="Center" HorizontalOptions="Center">
  2. <StackLayout IsVisible="{Binding Source={x:Reference SerieRadioButton}, Path=IsChecked}">
  3. <Label Text="Temporadas" FontSize="16" />
  4. <Entry x:Name="SeasonsEntry" Placeholder="Ingrese el número de temporadas" />
  5. <Label Text="Duración promedio del episodio" FontSize="16" />
  6. <Entry x:Name="AverageEpisodeDurationEntry" Placeholder="Ingrese la duración promedio del episodio" />
  7. <Label Text="Es Anime" FontSize="16" />
  8. <Switch x:Name="IsAnimeSwitch" />
  9. <Label Text="Está completado" FontSize="16" />
  10. <Switch x:Name="IsCompletedSwitch" />
  11. </StackLayout>
  12. <StackLayout IsVisible="{Binding Source={x:Reference PeliculaRadioButton}, Path=IsChecked}">
  13. <Label Text="Duración" FontSize="16" />
  14. <Entry x:Name="DurationEntry" Placeholder="Ingrese la duración" />
  15. <Label Text="Edad recomendada" FontSize="16" />
  16. <Entry x:Name="RecommendedAgeEntry" Placeholder="Ingrese la edad recomendada" />
  17. <Label Text="Ganador de premios" FontSize="16" />
  18. <Switch x:Name="AwardWinnerSwitch" />
  19. </StackLayout>
  20. <StackLayout IsVisible="{Binding Source={x:Reference VideojuegoRadioButton}, Path=IsChecked}">
  21. <Label Text="Plataformas" FontSize="16" />
  22. <Entry x:Name="PlatformsEntry" Placeholder="Ingrese las plataformas" />
  23. <Label Text="Modos de juego" FontSize="16" />
  24. <Entry x:Name="GameModesEntry" Placeholder="Ingrese los modos de juego" />
  25. <Label Text="Es original" FontSize="16" />
  26. <Switch x:Name="IsOriginalSwitch" />
  27. <Label Text="Está inspirado" FontSize="16" />
  28. <Switch x:Name="IsInspiredSwitch" />
  29. </StackLayout>

答案1

得分: 2

I do not know if you understand it, but you are actually writing a TAB control. (RadioButtons controlling the visibility of layouts)

This is how naming a control is done:

x:Name="controlName"

The Value you set here:

<RadioButton Value="Serie" Margin="20" >

does not mean a thing in your case. If you are going to use references, you might as well do all this work instead in the code.

What you should actually do is, make a radio button group:

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/radiobutton

And then use the selected value.

...RadioButtonGroup.SelectedValue="{Binding Selection}">

After you have the selected value, you can approach the "visibility" by different ways:

You can bind it to the selection itself, with using https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/data-binding/converters

Or you can switch between the layouts:
https://learn.microsoft.com/en-us/dotnet/maui/user-interface/layouts/bindablelayout

You might as well search for ready-to-use TabControls.

英文:

I do not know if you understand it, but you are actually writing a TAB control. (RadioButtons controlling the visibility of layouts)

This is how naming a control is done:

  1. x:Name=&quot;controlName&quot;

The Value you set here:

  1. &lt;RadioButton Value=&quot;Serie&quot; Margin=&quot;20&quot; &gt;

does not mean a thing in your case. If you are going to use references, you might as well do all this work instead in the code.

What you should actually do is, make a radio button group:

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/radiobutton

And then use the selected value.

  1. ...RadioButtonGroup.SelectedValue=&quot;{Binding Selection}&quot;&gt;

After you have the selected value, you can approach the "visibility" by different ways:

You can bind it to the selection itself, with using https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/data-binding/converters

Or you can switch between the layouts:
https://learn.microsoft.com/en-us/dotnet/maui/user-interface/layouts/bindablelayout

You might as well search for ready-to-use TabControls.

huangapple
  • 本文由 发表于 2023年6月13日 16:31:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76463033.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定