点击并按住列表框Windows Phone

时间:2014-01-30 07:15:55

标签: c# xaml windows-phone-8 listbox

有人知道每当我按下listbox时我会如何添加事件,它会直接运行我的代码。我需要它来更改我的listbox所选项目。这是我的xaml

<ListBox x:Name="ListNabi" SelectionChanged="ListNabi_SelectionChanged" ItemsSource="{Binding}" Tap="ListNabi_Tap" Hold="ListNabi_Hold">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Margin="5,0,5,0">
                <!--<Image Source="{Binding ImageSource}" Stretch="None"/>-->
                <Grid Width="480" Background="White">
                    <Image x:Name="listDaun" Source="/Images/Button/Button List.png"
                     Margin="0,5,5,5" Width="38" HorizontalAlignment="Left"></Image>
                    <TextBlock x:Name="namaNabi"  TextWrapping="NoWrap" 
                     Text="{Binding Name}" FontFamily="{StaticResource PhoneFontFamilyNormal}" 
                     FontSize="36" Foreground="#00ADCE" Margin="40,5,0,5"></TextBlock>
                    <Rectangle Margin="0,50,0,0" Height="2" Fill="#00ADCE" Width="480"/>
                </Grid>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

在CS中,我确实喜欢这样:

private void ListNabi_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
    changeColor("#00ADCE", "#FFFFFF", "#FFFFFF", "/Images/Button/Button List1.png");
}

private void ListNabi_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    if (ListNabi.SelectedIndex != -1)
    {
        id = ListNabi.SelectedIndex;
    }
    MessageBox.Show("tes");
    changeColor("#00ADCE", "#FFFFFF", "#FFFFFF", "/Images/Button/Button List1.png");
}

private void ListNabi_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (ListNabi.SelectedIndex != -1)
    {
        id = ListNabi.SelectedIndex;
        changeColor("#00ADCE", "#FFFFFF", "#FFFFFF", "/Images/Button/Button List1.png");
        NavigationService.Navigate(new Uri("/Pages/25_Nabi/DetailPage.xaml?id="
        + ListNabi.SelectedIndex, UriKind.Relative));
        ListNabi.SelectedIndex = -1;
    }
}

但是只要我在一段时间后或在我松开手指后按住changeColor(),它就会运行我的代码(在此上下文listbox中)。是否有任何事件可以用来在我的手指开始触摸时开始运行我的代码?

1 个答案:

答案 0 :(得分:0)

为此,请使用以下事件:ManipulationStartedManipulationDeltaManipulationCompleted。从位置到不同接触点的数量,您将获得所需的一切。

你可以用它做一些复杂的事情,比如拖拽和捏。