<ListView Margin="25" BorderThickness="0" Background="#262A30" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" x:Name="listview" Foreground="White"> <ListView.ItemTemplate> <DataTemplate> <Grid Margin="10,15,0,15" Background="#262A30"> <Grid.RowDefinitions> <RowDefinition ></RowDefinition> <RowDefinition ></RowDefinition> <!--<RowDefinition Height="Auto"></RowDefinition>--> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <Grid Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Background="White" Margin="10,15,15,40"> <Grid.RowDefinitions> <RowDefinition Height="3*"></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <Image Margin="3" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Source="{Binding EventPicPath}" Height="140" Width="160" ></Image> <TextBlock Margin="3" Grid.Row="1" Grid.Column="0" Text="{Binding StartTime}" Foreground="Black" VerticalAlignment="Center"></TextBlock> <Image x:Name="imgEditEvent" Tag="{Binding EventId}" MouseLeftButtonUp="imgEditEvent_MouseLeftButtonUp" Margin="3" Grid.Row="1" Grid.Column="1" Source="..\Image\eventEdit.PNG" Width="20" Height="20"></Image> <Image x:Name="imgDelEvent" Tag="{Binding EventId}" MouseLeftButtonUp="imgDelEvent_MouseLeftButtonUp" Margin="3" Grid.Row="1" Grid.Column="2" Source="..\Image\eventDelete.PNG" Width="20" Height="20"></Image> </Grid> <StackPanel Grid.Row="0" Grid.Column="1"> <Line Stroke="Gray" X1="5" Y1="10" X2="5" Y2="150" Margin="10"></Line> </StackPanel> <DockPanel Grid.Row="0" Grid.Column="2"> <Image x:Name="imgLastPre" MouseLeftButtonUp="imgLastPre_MouseLeftButtonUp" Source="..\Image\leftPre.PNG"></Image> </DockPanel> <ScrollViewer x:Name="svPre" Grid.Row="0" Grid.Column="3" VerticalScrollBarVisibility="Hidden"> <ListView x:Name="lvPres" Height="120" BorderThickness="0" BorderBrush="#262A30" Width="610" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemsSource="{Binding PreCollection}" Background="#262A30"> <ListView.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Orientation="Horizontal" IsItemsHost="True"></WrapPanel> </ItemsPanelTemplate> </ListView.ItemsPanel> <ListView.ItemTemplate> <DataTemplate> <Image x:Name="imgPre" Source="{Binding PrePicPath}" Tag="{Binding EventId}" Margin="15,0,15,0" Height="100" Width="120" MouseLeftButtonUp="imgPre_MouseLeftButtonUp"></Image> </DataTemplate> </ListView.ItemTemplate> </ListView> </ScrollViewer>
红色的部分 名为imgLastPre的Image 和名为svPre的scrollviewer 都在 一个外层 listview的数据模板中 ,现在 要通过 imgLastPre 的 MouseLeftButtonUp事件 获取 svPre控件 请问 该如何做,控件虽然都有名字 但是 在 codebehind中 获取不到 估计是 在数据模板中的原因 请各路大神 指点 不吝加分 。
找子控件
已解决。。。