简体   繁体   中英

Get previous item in grid winrt

<Grid x:Name="gridGeneralProperties" HorizontalAlignment="Left" Height="613" Margin="233,5,0,0" Grid.Row="1" VerticalAlignment="Top" Width="437">
    <TextBlock TextWrapping="Wrap" Text="General Properties" FontSize="16" Margin="162,10,18,573"/>
    <TextBlock TextWrapping="Wrap" Text="Name" Margin="10,69,298,521" FontSize="14.667"/>
    <TextBox TextWrapping="Wrap" Text="{Binding Document.DocumentName}" IsReadOnly="True" Margin="144,59,73,520"/>
    <AppBarButton x:Name="appBarButtonEditName" HorizontalAlignment="Left" Label="" Margin="349,39,-12,0" VerticalAlignment="Top" Icon="Edit" Height="75"/>
</Grid>

Is there a way to access the previous in a grid? In this case, if a user clicks on the AppBarButton, I want to make the previous TextBox editable. In all instances of where the button is clicked, the previous item will be a TextBox.

In your case - you know which one is previous in your XAML - you can simply name it to access it.

The general solution would be to get the index of the starting element in the Grid.Children collection and the previous one will be at index - 1.

MVVM is the way to go though. I'm also not sure why you would need a button to make a TextBox editable - just leave it editable always and you save the space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM