窗口电话 - 如何禁用当前选择项?

时间:2014-05-15 04:46:39

标签: xaml windows-phone

我有一个xaml:

<phone:LongListSelector Name="llsSourceNews"  ItemsSource="{Binding SourceNews}">
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <Grid x:Name="gridNews">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="80" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="120"/>
                        <ColumnDefinition Width="250"/>
                        <ColumnDefinition Width="40"/>
                    </Grid.ColumnDefinitions>
                    <Image Grid.Row="0" Grid.Column="0" Source="{Binding icon}" Stretch="Fill" Height="35" Width="70"></Image>
                    <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Name}" Foreground="White" TextWrapping="Wrap" FontSize="24" VerticalAlignment="Center"></TextBlock>
                    <Image Grid.Row="0" Grid.Column="2" Source="/Images/Add-New.png" x:Name="imgAdd"  Tap="imgAdd_Tap"></Image>
                </Grid>
            </DataTemplate>
        </phone:LongListSelector.ItemTemplate>
    </phone:LongListSelector>

并点按事件:

private void imgAdd_Tap(object sender, System.Windows.Input.GestureEventArgs e)
   {
       if(true)
       {
        this.Visibility = Visibility.Collapsed;
       }
    }

我的问题是:当用户点击图像时,所有图像都被禁用。我想图像被禁用,这是被选中的。

1 个答案:

答案 0 :(得分:1)

您的案例中的

this指的是该页面。如果要检索图像,则必须转换sender参数:

private void imgAdd_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    if(true)
    {
        var element = (FrameworkElement)sender;
        element.Visibility = Visibility.Collapsed;
    }
}