0

要約すると、コマンドをデータ テンプレートにバインドしようとしています。ユーザーがデータのブロックをタップすると、View Model のコマンドが実行されます。

ボタンを View Model コマンドにバインドする (貧弱な) コードを貼り付けましたが、ボタンなしでデータ ブロック全体のタップをバインドする方法がわかりません。

基本的に、ユーザーはテキストブロックを保持している StackPanel をタップして LoadDataCommand を起動するだけです。スタック パネルのボタンでコマンドを実行したくありません。以下のコードは私の通常のコーディング方法ではありません。ただ実験しているだけです... fyi :)

私はWP8用に開発しています。私はMVVM Lightを使用していません。MVVM Light ライブラリのみの EventToCommand を使用してみましたが、どうやら WP8 では動作しないようです。任意の提案をいただければ幸いです!

        <phone:LongListSelector x:Name="CredList" Margin="0,300,0,0" ItemsSource="{Binding DataSource}">
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Vertical">
                    <StackPanel Orientation="Vertical" Margin="0,15,0,0">
                        <Button Command="{Binding Path=DataContext.LoadDataCommand, ElementName=CredList}" />
                        <TextBlock Text="{Binding DisplayName}" />
                        <TextBlock Text="{Binding Username}" />
                        <TextBlock Text="{Binding Password}" />
                    </StackPanel>
                    <Line X1="2" Y1="0" X2="1" Y2="0" Stretch="Fill" Stroke="AntiqueWhite" StrokeThickness="0.5" />
                </StackPanel>
            </DataTemplate>
        </phone:LongListSelector.ItemTemplate>
    </phone:LongListSelector>
4

0 に答える 0