我有这个长列表选择器:
<phone:LongListSelector Background="Transparent" x:Name="DocSummaries" ItemTemplate="{StaticResource DataTemplate_Header}" ItemsSource="{Binding DocumentHeaders}" Margin="33,0,-5,0"/>
并且该列表使用此 itemtemplate :
<Viewbox x:Name="viewboxHeader" Tag="0">
<StackPanel Orientation="Vertical" x:Name="listStackpanel" Height="330" Width="410" Margin="0,10,0,8">
<Grid x:Name="HeaderGrid" Margin="0,0,0,0" Height="325" Width="410" Background="#FF4A4A4A" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<!--<TextBlock x:Name="txtduration" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5" FontSize="{StaticResource PhoneFontSizeNormal}" Text="{Binding Transaction.Duration}" Foreground="{Binding Transaction.Urgency, Converter={StaticResource converttocolor}}" TextAlignment="Left" Width="60" Height="28" Canvas.Left="-26" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-18,0,0,25" >
</TextBlock>
<TextBlock x:Name="txtdays" TextWrapping="Wrap" Text="days" Foreground="{Binding Transaction.Urgency, Converter={StaticResource converttocolor}}" RenderTransformOrigin="0.5,0.5" FontSize="{StaticResource PhoneFontSizeSmall}" TextAlignment="Left" Width="45" Height="28" Canvas.Left="-26" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="3,0,0,10" >
</TextBlock>-->
<CheckBox x:Name="chkSelect" Grid.Row="0" Grid.Column="0" Grid.RowSpan="6" VerticalAlignment="Center" Width="Auto" Checked="chkSelect_Checked" Unchecked="chkSelect_Unchecked"/>
<StackPanel Grid.Row="0" Grid.Column="2" Margin="15,0,0,5" x:Name="Durationpanel" Background="#FF4A4A4A" HorizontalAlignment="Right" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Margin="2" FontSize="22" x:Name="txtDuration" Text="{Binding Duration}" Foreground="{Binding Urgency, Converter={StaticResource converttocolor}}" HorizontalAlignment="Right"></TextBlock>
<TextBlock TextWrapping="Wrap" Margin="2,4,2,2" FontSize="22" Foreground="{Binding Urgency, Converter={StaticResource converttocolor}}" Text="days" HorizontalAlignment="Right"></TextBlock>
</StackPanel>
<TextBlock Grid.Row="1" Grid.Column="1" Tap="btnViewDetail_Tap" Margin="0" Grid.ColumnSpan="2" TextWrapping="Wrap" Text="{Binding DocDesc}" FontSize="30" Foreground="#FFDFDFDF" >
</TextBlock>
<TextBlock TextWrapping="Wrap" Margin="0" Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="1" Text="{Binding Created}" FontSize="16" Foreground="#FFDFDFDF">
</TextBlock>
<TextBlock TextWrapping="Wrap" Grid.Row="3" Grid.ColumnSpan="2" Grid.Column="1" Margin="0" Text="{Binding Actioned}" Foreground="#FFDFDFDF" FontSize="16">
</TextBlock>
<TextBlock Grid.Row="4" Grid.Column="1" Margin="0,5,0,0" Foreground="#FFDFDFDF" FontSize="16" Text="{Binding Info1Label}"></TextBlock>
<TextBox Grid.Row="4" HorizontalAlignment="Stretch" Grid.Column="2" Height="55" FontSize="16" Margin="0,0,0,-15" Text="{Binding Info1Value}"></TextBox>
<TextBlock Grid.Row="5" Grid.Column="1" Foreground="#FFDFDFDF" FontSize="16" Text="{Binding Info2Label}" ></TextBlock>
<TextBox Grid.Row="5" HorizontalAlignment="Stretch" Grid.Column="2" Height="55" FontSize="16" Margin="0,0,0,-15" Text="{Binding Info2Value}"></TextBox>
<TextBlock Grid.Row="6" Grid.Column="1" Foreground="#FFDFDFDF" FontSize="16" Text="{Binding Info3Label}"></TextBlock>
<TextBox Grid.Row="6" HorizontalAlignment="Stretch" Grid.Column="2" Height="55" FontSize="16" Margin="0,0,0,-15" Text="{Binding Info3Value}"></TextBox>
</Grid>
</StackPanel>
</Viewbox>
现在我的问题是,我想在 longlistselector 中的 itemtemplate 中获取复选框,这样如果用户单击一个复选框,其他复选框就会被取消选中。
在下面的代码中,我得到了 longlistselector,但现在我不知道如何从 itemtemplate 中获取复选框。
foreach (var thisthing in LayoutRoot.Children)
{
if (thisthing.GetType() == typeof(Grid))
{
Grid myGrid = (thisthing as Grid);
foreach (var Mylist in myGrid.Children)
{
if (Mylist.GetType() == typeof(LongListSelector))
{
LongListSelector FoundList = (Mylist as LongListSelector);
}
}
}
}
如果有人可以在这里帮助我,我将不胜感激。
使用 Visual Studio 2012,c# Windows phone 8 应用程序