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

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

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:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:GameVidNet"
             x:Class="GameVidNet.Paginas.NewMediaPage"
             Title="NewMediaPage">

    <Grid>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <StackLayout Padding="20" VerticalOptions="Center" HorizontalOptions="Center" Grid.Column="0" >
            
            <Label Text="Tipo de Media" FontSize="16" />
            <HorizontalStackLayout>
                <RadioButton Value="Serie" Margin="20" >
                    <RadioButton.Content>
                        <Image Source="series.png" HeightRequest="30" WidthRequest="30"/>
                    </RadioButton.Content>
                </RadioButton>
                <RadioButton Value="Pelicula" Margin="20" >
                    <RadioButton.Content>
                        <Image Source="movie.png" HeightRequest="30" WidthRequest="30"/>
                    </RadioButton.Content>
                </RadioButton>
                <RadioButton Value="Videojuego" Margin="20" >
                    <RadioButton.Content>
                        <Image Source="videogame.png" HeightRequest="30" WidthRequest="30"/>
                    </RadioButton.Content>
                </RadioButton>
            </HorizontalStackLayout>

            <Label Text="ID" FontSize="16" />
            <Entry x:Name="IdEntry" Placeholder="Ingrese el ID" />

            <Label Text="Título" FontSize="16" />
            <Entry x:Name="TitleEntry" Placeholder="Ingrese el título" />

            <Label Text="Género" FontSize="16" />
            <Entry x:Name="GenreEntry" Placeholder="Ingrese el género" />

            <Label Text="Año de Lanzamiento" FontSize="16" />
            <Entry x:Name="ReleaseYearEntry" Placeholder="Ingrese el año de lanzamiento" />

            <Button Text="Guardar" Clicked="SaveButton_Clicked" Margin="0,20,0,0" />
            
        </StackLayout>

        
        <StackLayout Grid.Column="1" Padding="20" VerticalOptions="Center" HorizontalOptions="Center">

            <StackLayout >
                <Label Text="Temporadas" FontSize="16" />
                <Entry x:Name="SeasonsEntry" Placeholder="Ingrese el número de temporadas" />

                <Label Text="Duración promedio del episodio" FontSize="16" />
                <Entry x:Name="AverageEpisodeDurationEntry" Placeholder="Ingrese la duración promedio del episodio" />

                <Label Text="Es Anime" FontSize="16" />
                <Switch x:Name="IsAnimeSwitch" />

                <Label Text="Está completado" FontSize="16" />
                <Switch x:Name="IsCompletedSwitch" />
            </StackLayout>

            <StackLayout >
                <Label Text="Duración" FontSize="16" />
                <Entry x:Name="DurationEntry" Placeholder="Ingrese la duración" />

                <Label Text="Edad recomendada" FontSize="16" />
                <Entry x:Name="RecommendedAgeEntry" Placeholder="Ingrese la edad recomendada" />

                <Label Text="Ganador de premios" FontSize="16" />
                <Switch x:Name="AwardWinnerSwitch" />
            </StackLayout>

            <StackLayout >
                <Label Text="Plataformas" FontSize="16" />
                <Entry x:Name="PlatformsEntry" Placeholder="Ingrese las plataformas" />

                <Label Text="Modos de juego" FontSize="16" />
                <Entry x:Name="GameModesEntry" Placeholder="Ingrese los modos de juego" />

                <Label Text="Es original" FontSize="16" />
                <Switch x:Name="IsOriginalSwitch" />

                <Label Text="Está inspirado" FontSize="16" />
                <Switch x:Name="IsInspiredSwitch" />
            </StackLayout>

        </StackLayout>
        
        
    </Grid>

    
</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.

<StackLayout Grid.Column="1" Padding="20" VerticalOptions="Center" HorizontalOptions="Center">

            <StackLayout IsVisible="{Binding Source={x:Reference SerieRadioButton}, Path=IsChecked}">
                <Label Text="Temporadas" FontSize="16" />
                <Entry x:Name="SeasonsEntry" Placeholder="Ingrese el número de temporadas" />

                <Label Text="Duración promedio del episodio" FontSize="16" />
                <Entry x:Name="AverageEpisodeDurationEntry" Placeholder="Ingrese la duración promedio del episodio" />

                <Label Text="Es Anime" FontSize="16" />
                <Switch x:Name="IsAnimeSwitch" />

                <Label Text="Está completado" FontSize="16" />
                <Switch x:Name="IsCompletedSwitch" />
            </StackLayout>

            <StackLayout IsVisible="{Binding Source={x:Reference PeliculaRadioButton}, Path=IsChecked}">
                <Label Text="Duración" FontSize="16" />
                <Entry x:Name="DurationEntry" Placeholder="Ingrese la duración" />

                <Label Text="Edad recomendada" FontSize="16" />
                <Entry x:Name="RecommendedAgeEntry" Placeholder="Ingrese la edad recomendada" />

                <Label Text="Ganador de premios" FontSize="16" />
                <Switch x:Name="AwardWinnerSwitch" />
            </StackLayout>

            <StackLayout IsVisible="{Binding Source={x:Reference VideojuegoRadioButton}, Path=IsChecked}">
                <Label Text="Plataformas" FontSize="16" />
                <Entry x:Name="PlatformsEntry" Placeholder="Ingrese las plataformas" />

                <Label Text="Modos de juego" FontSize="16" />
                <Entry x:Name="GameModesEntry" Placeholder="Ingrese los modos de juego" />

                <Label Text="Es original" FontSize="16" />
                <Switch x:Name="IsOriginalSwitch" />

                <Label Text="Está inspirado" FontSize="16" />
                <Switch x:Name="IsInspiredSwitch" />
            </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:

 x:Name=&quot;controlName&quot;

The Value you set here:

&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.

...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:

确定