0

ListBox の DataTemplate 内に ContextMenu を配置しようとしています。ListBox は PivotItem 内に配置されます。何らかの理由で、ListBox 内の項目が押された状態で ContextMenu が表示されません。エラーリストまたはデバッグ中に何も表示されないため、エラーが不明です。

MainPage.xaml

<phone:PhoneApplicationPage.Resources>
    <Style x:Key="MyStyle" TargetType="ListBoxItem">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property ="Foreground" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border x:Name="LayoutRoot" Background="{TemplateBinding Background}" 
            HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
            VerticalAlignment="{TemplateBinding VerticalAlignment}" 
            BorderBrush="{TemplateBinding BorderBrush}" 
            BorderThickness="{TemplateBinding BorderThickness}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver" />
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Storyboard.TargetName="ContentContainer" Storyboard.TargetProperty="Opacity" Duration="0" To=".5" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected"/>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="brd"
                                Storyboard.TargetProperty="BorderThickness">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="2" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="brd" CornerRadius="10" BorderBrush="{StaticResource PhoneAccentBrush}" Width="Auto" BorderThickness="{TemplateBinding BorderThickness}">
                            <Image x:Name="recentImage" Source="{Binding Source}" Margin="12" Width="115"/>                                
                        </Border>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</phone:PhoneApplicationPage.Resources>

<phone:PivotItem Header="recent">
            <ListBox x:Name="Recent" ItemsSource="{Binding Pictures}" Margin="8" 
                     SelectionChanged="recent_SelectionChanged" toolkit:TiltEffect.IsTiltEnabled="True"
                     ItemContainerStyle="{StaticResource MyStyle}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu x:Name="imgListContextMenu">
                                <toolkit:MenuItem Header="share" Tap="shareContextMenuItem_Tap"/>
                                <toolkit:MenuItem Header="favorite" Tap="favoriteContextMenuItem_Tap"/>
                                <toolkit:MenuItem Header="set as start screen" Tap="setAsStartScreenContextMenuItem_Tap"/>
                                <toolkit:MenuItem Header="delete" Tap="deleteContextMenuItem_Tap"/>
                            </toolkit:ContextMenu>
                        </toolkit:ContextMenuService.ContextMenu>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
         </phone:PivotItem>

また、Tap は、各 ContextMenu アイテム内で使用するのに最適なイベント ハンドラー メソッドですか?

4

2 に答える 2

0

ListBox には独自のカスタム スタイルがあるため、画像バインディングが発生する場所の下にコンテキスト メニューを配置しました。

VisualStateManager の終了タグの下..

</VisualStateManager.VisualStateGroups>
                        <Border x:Name="brd" CornerRadius="10" BorderBrush="{StaticResource PhoneAccentBrush}" Width="Auto" BorderThickness="{TemplateBinding BorderThickness}">
                            <Image x:Name="recentImage" Source="{Binding Source}" Margin="12" Width="115"/>                                
                        </Border>
                        <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu x:Name="imgListContextMenu">
                                ...
                            </toolkit:ContextMenu>
                        </toolkit:ContextMenuService.ContextMenu>
于 2013-06-23T13:05:42.930 に答える