-1

重複の可能性:
Tag プロパティで XAML 要素を取得する方法はありますか?

私はこのようなコードを持っています:

                <ListBox x:Name="ImageListBox"  ScrollViewer.VerticalScrollBarVisibility="Disabled"
                     Height="100"  >

                    <ListBox.ItemsPanel >
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel  ItemHeight="100" ItemWidth="110" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>

                <ListBox.ItemTemplate>
                        <DataTemplate>
                        <Grid Tap="StackPanel_Tap" Tag="{Binding Type}" Name="Yashu">
                            <Border BorderThickness="{Binding Thickness}"  CornerRadius="0"   BorderBrush="White" Width="100" Height="100"  HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="1" >
                                <!--<Grid>-->
                                <Image Tag="{Binding Type}" Source="{Binding Location}" Opacity="1" Width="100"  Height="100" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" UseLayoutRounding="True"  >
                                </Image>
                            </Border>

                        </Grid>
                    </DataTemplate>
                    </ListBox.ItemTemplate>
            </ListBox>
        </ScrollViewer>

タグ名でListBoxのグリッド要素を取得する方法は?

4

1 に答える 1

0

イベント ハンドラーStackPanel_Tapで、センダーをグリッドに変換します。

object tag = (sender as Grid).Tag;

グリッド要素の使用を取得するにはGrid grid1 = sender as Grid;

注: これは、ユーザーが項目をタップした場合にのみ機能します。役立つことを願っています

于 2012-09-14T05:27:58.197 に答える