【问题标题】:listbox with image tap带有图像点击的列表框
【发布时间】:2014-02-07 03:50:52
【问题描述】:

如何实现这个ui?

项目1 | X 项目2 | X 项目3 | X

item1,item2,item3 有 SelectionChanged 事件,X 是带有点击事件的图像

我试过了

<telerikPrimitives:RadDataBoundListBox
    x:Name="AddressListBox"
    ItemsSource="{Binding hereRestAddressDetail}"
    SelectedItem="{Binding hereRestDetail}"
    SelectionChanged="AddressListBox_SelectionChanged" 
    ItemAnimationMode="PlayAll"
    EmptyContent="">
    <telerikPrimitives:RadDataBoundListBox.ItemTemplate>
        <DataTemplate>
            <Grid Margin="0,0,0,10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Rectangle Grid.Column="0" Grid.RowSpan="2" Width="10">
                    <Rectangle.Fill>
                        <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                    </Rectangle.Fill>
                </Rectangle>
                <StackPanel Grid.Column="1" Grid.RowSpan="2" >
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding LocalizedResources.by, 
                                            Source={StaticResource LocalizedStrings}}" 
                                   Style="{StaticResource PhoneTextNormalStyle}"/>
                        <TextBlock Text="{Binding creator}" Margin="-8,0,0,0"
                                   Style="{StaticResource PhoneTextAccentStyle}"/>
                    </StackPanel>
                    <TextBlock Text="{Binding street}"
                               TextWrapping="Wrap"
                               Style="{StaticResource PhoneTextLargeStyle}" />
                    <TextBlock Text="{Binding formatedStreet}" 
                               TextWrapping="Wrap"
                               Style="{StaticResource PhoneTextSubtleStyle}" />
                </StackPanel>
                <Image Source="{Binding ratingButton}" Grid.Column="2" 
                       Stretch="Uniform" Width="80"
                       Tag="{Binding Id}" Tap="rate_Tap"/>
                <TextBlock Text="{Binding ratingValue}" HorizontalAlignment="Center"
                           TextWrapping="Wrap" Grid.Column="2" Grid.Row="1"
                           Style="{StaticResource PhoneTextSubtleStyle}"/>
            </Grid>
        </DataTemplate>
    </telerikPrimitives:RadDataBoundListBox.ItemTemplate>

</telerikPrimitives:RadDataBoundListBox>

但是当我点击图像时,它会执行我的事件(在这种情况下,我只是通过显示 messagebox 来测试它)但之后它也会执行我的 SelectionChanged 事件...

如何指定只有点击图片时触发的图片点击事件?

【问题讨论】:

    标签: c# xaml telerik windows-phone


    【解决方案1】:

    这应该可行:

    bool ignoreSelectionChanged;
    void rate_Tap(...) {
        ignoreSelectionChanged = true;
        //do you image tap things here
    }
    void AddressListBox_SelectionChanged(...) {
        if(ignoreSelectionChanged) {
            ignoreSelectionChanged = false; //reset the bool, so that it will skip only once
            return;
        }
        //do your things on selection change here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多