简体   繁体   English

获取网格Winrt中的上一个项目

[英]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. 在这种情况下,如果用户单击AppBarButton,则我想使以前的TextBox可编辑。 In all instances of where the button is clicked, the previous item will be a TextBox. 在单击按钮的所有情况下,上一项都是TextBox。

In your case - you know which one is previous in your XAML - you can simply name it to access it. 对于您的情况-您知道XAML中的哪个是以前的-您只需命名它即可访问它。

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. 通用解决方案是获取Grid.Children集合中起始元素的索引,而前一个元素将位于索引-1处。

MVVM is the way to go though. MVVM是要走的路。 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. 我也不确定为什么需要一个按钮来使TextBox可编辑-始终将其保留为可编辑状态,这样可以节省空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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