3

ページがあり、ビューモデルがそのデータコンテキストとして設定されています。そのページにリストがあります。ビューモデルのプロパティを介して設定されています。リストにはユーザー コントロールがあります。そのユーザーコントロールにはボタンがあります。そのボタンをviewmodelにあるコマンドにバインドしたい。とにかくそれを行うことはありますか?

<Page DataContext=PageViewModel>
...
<ScrollViewer Grid.Row="3" Margin="20,0" Visibility="{Binding ByVenueSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
                <StackPanel>
                    <ItemsControl ItemsSource="{Binding EventsListByVenue}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <myControls:EventDetails /> <!--in this control i want to bind a command available in PageViewModel-->
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </StackPanel>
            </ScrollViewer>
...
</Page>
4

1 に答える 1

0

@FunksMaName の助けを借りて、これを解決しました。もっとエレガントでより良いアプローチがあると確信していますが、これは私にとって迅速で簡単な解決策です:

<Button Style="{StaticResource NoHighlightButtonStyle}" Tag="{Binding link}" CommandParameter="{Binding Path=Tag,RelativeSource={RelativeSource Mode=Self}}" Visibility="{Binding link,Converter={StaticResource DataAvailabilityToVisibilityConverter}}" Command="{Binding Path=Event.LinkCommand,Source={StaticResource Locator}}" >
                <TextBlock Margin="0,5" Foreground="SkyBlue" Text="{Binding link}" TextWrapping="Wrap" FontSize="16"/>
</Button>

注意事項:xamlはコマンドのコンテキストでのみコマンドパラメーターを検索したと思うので、同じバインディングがボタン内のテキストブロックに対して正常に機能している間、nullパラメーターが与えられました。だから私はそれをだましてタグに値を保存し、そこからそれを使用しました。

Tag="{Binding link}" CommandParameter="{Binding Path=Tag,RelativeSource={RelativeSource Mode=Self}}"
于 2013-09-18T11:33:23.273 に答える