0

Channel9 の Absolute Beginners Series をフォローしていますが、何か他のことを学ぶための挑戦として、シリーズで紹介されていないいくつかの機能を実装するように言われました.

私たちが持っているのは、DataTemplateいくつかの「タイル」のようなコントロールを構築するために使用され、LongListSelector.

私がする必要があるのは、これらのタイルにコンテキスト メニューを追加して、追加の操作を実行することです。

現在、これらの操作の 1 つは、特定のタイプのタイルでのみ実行する必要があります。これは、LongListSelector.

ページコードは次のとおりです。

<phone:PhoneApplicationPage
    x:Class="SoundBoard.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    mc:Ignorable="d"
    d:DataContext="{d:DesignData SampleData/SampleData.xaml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="SoundTileDataTemplate">            
            <Grid Name="TileGrid" Background="{StaticResource PhoneAccentBrush}" Margin="0,0,12,12">
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu>
                        <toolkit:MenuItem Header="{Binding Path=LocalizedResources.PinToStartMessage, Source={StaticResource LocalizedStrings}}"/>
                        <toolkit:MenuItem IsEnabled="False" Header="{Binding Path=LocalizedResources.DeleteSoundMessage, Source={StaticResource LocalizedStrings}}"/>
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
                <Grid VerticalAlignment="Top" HorizontalAlignment="Right" Width="40" Height="40" Margin="0,6,6,0">
                    <Ellipse Stroke="{StaticResource PhoneForegroundBrush}" StrokeThickness="3"/>
                    <Image Source="/Assets/AppBar/Play.png"></Image>
                </Grid>
                <StackPanel VerticalAlignment="Bottom">
                    <TextBlock Text="{Binding Title}" Margin="6,0,0,6"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <MediaElement Name="AudioPlayer" Volume="1"/>

        <phone:Pivot Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}">
            <phone:PivotItem Header="{Binding Animals.Title}">    
                <phone:LongListSelector Margin="0,0,-12,0" ItemsSource="{Binding Animals.Items}" LayoutMode="Grid" GridCellSize="150,150" ItemTemplate="{StaticResource SoundTileDataTemplate}" SelectionChanged="LongListSelector_SelectionChanged">
                </phone:LongListSelector>
            </phone:PivotItem>

            <phone:PivotItem Header="{Binding Cartoons.Title}">

                <phone:LongListSelector Margin="0,0,-12,0" ItemsSource="{Binding Cartoons.Items}" LayoutMode="Grid" GridCellSize="150,150" ItemTemplate="{StaticResource SoundTileDataTemplate}" SelectionChanged="LongListSelector_SelectionChanged">
                </phone:LongListSelector>
            </phone:PivotItem>

            <phone:PivotItem Header="{Binding Taunts.Title}">
                <phone:LongListSelector Margin="0,0,-12,0" ItemsSource="{Binding Taunts.Items}" LayoutMode="Grid" GridCellSize="150,150" ItemTemplate="{StaticResource SoundTileDataTemplate}" SelectionChanged="LongListSelector_SelectionChanged">
                </phone:LongListSelector>
            </phone:PivotItem>

            <phone:PivotItem Header="{Binding Warnings.Title}">               
                <phone:LongListSelector Margin="0,0,-12,0" ItemsSource="{Binding Warnings.Items}" LayoutMode="Grid" GridCellSize="150,150" ItemTemplate="{StaticResource SoundTileDataTemplate}" SelectionChanged="LongListSelector_SelectionChanged">
                </phone:LongListSelector>
            </phone:PivotItem>

            <phone:PivotItem Header="{Binding CustomSounds.Title}">                
                <phone:LongListSelector Margin="0,0,-12,0" ItemsSource="{Binding CustomSounds.Items}" LayoutMode="Grid" GridCellSize="150,150" ItemTemplate="{StaticResource SoundTileDataTemplate}" SelectionChanged="LongListSelector_SelectionChanged">
                </phone:LongListSelector>
            </phone:PivotItem>
        </phone:Pivot>

    </Grid>

</phone:PhoneApplicationPage>

今、私がする必要があるToolkit:MenuItemのは、コントロールが最後の にロードされたときにのみ2 番目を有効にすることLongListSelectorです。

アイテムのアイテムにタイプIsEnabledがある場合にtrueを返すブール式をアイテムに書き込むことは可能ですか、またはこの状況を処理するために2つの異なるものを書く必要がありますか?DataTemplateCustomSoundsDataTemplate

編集:いくつかのコードを変更しました

<phone:PhoneApplicationPage
x:Name="SBMainPage"
...
    <toolkit:MenuItem IsEnabled="{Binding Path=IsDeleteEnabled, ElementName=SBMainPage}" Header="{Binding Path=LocalizedResources.DeleteSoundMessage, Source={StaticResource LocalizedStrings}}" Tap="DeleteSoundHandler"/>

しかし、プロパティによって返されるブール値はIsDeleteEnabled更新されないためfalse、プロパティが最初に読み取られたときに指定された値が取得され、変更されることはありません!

4

2 に答える 2

0

コンバーターはあなたが望むことをします:

class TypeToBoolConverter :IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return value.GetType() == typeof(CustomSounds);
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

そして、あなたが使用できること:

<toolkit:MenuItem IsEnabled="{Binding ,Converter={StaticResource myTypeConverter}}" ...
于 2013-09-12T19:26:29.200 に答える
0

IsDeleteEnabled が INotifyPropertyChanged に準拠していることを確認します。率直に言って、モデル ビューにブール値のステータス フラグを追加し、バインディングによってページ ロジックを接続するだけで、私はこれを行っています。

于 2013-09-12T19:26:29.980 に答える