1

我正在尝试绑定到 LoadSpacesCommand,它是 ViewModel 中我的 Dashboard 属性的一部分,如下所示:

    <DataTemplate x:Key="OrganisationsItemTemplate">
        <StackPanel VerticalAlignment="Top" Margin="5,0,0,0">
            <Button Command="{Binding LoadSpacesCommand}" CommandParameter="{Binding}" ...>
                <Grid Margin="0,0,5,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="67"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <StackPanel Grid.Column="0" Background="Transparent">
                        <Border Background="White" BorderThickness="0" Width="62" Height="62" HorizontalAlignment="Left" Margin="0,0,0,5">
                            <Image Source="{Binding image.thumbnail_link}" Width="62" Height="62"></Image>
                        </Border>
                    </StackPanel>
                    <StackPanel Grid.Column="1" VerticalAlignment="Center" Background="Transparent">
                        <TextBlock Text="{Binding name}" HorizontalAlignment="Left" FontSize="30" VerticalAlignment="Center" Margin="0,0,0,5" />
                    </StackPanel>
                </Grid>
            </Button>
        </StackPanel>
    </DataTemplate>

这是数据模板处理的项目:

        <phone:PanoramaItem Header="Organisations">
            <phone:LongListSelector x:Name="OrganisationList"
                                    JumpListStyle="{StaticResource OrganisationsJumpListStyle}"
                                    Background="Transparent"
                                    GroupHeaderTemplate="{StaticResource OrganisationsGroupHeaderTemplate}"
                                    ItemTemplate="{StaticResource OrganisationsItemTemplate}" 
                                    ItemsSource="{Binding Organisations}" 
                                    Margin="40,0,0,96" 
                                    LayoutMode="List"
                                    HideEmptyGroups="True"
                                    IsGroupingEnabled="True">

            </phone:LongListSelector>
            <!--<ListBox Name="Organisation" ItemTemplate="{StaticResource OrganisationTemplate}" ItemsSource="{Binding Organisations}" Margin="0,0,0,96" IsSynchronizedWithCurrentItem="False"/>-->
        </phone:PanoramaItem>

这是我的应用程序页面数据上下文:

...shell:SystemTray.IsVisible="False" DataContext="{Binding Dashboard}"

我需要在命令中输入什么来访问视图模型命令吗?

4

1 回答 1

2

您可以绑定回LongListSelectorusing ElementName,而DataContextfor 应该是您的ViewModel

Command="{Binding Path=DataContext.LoadSpacesCommand, ElementName=OrganisationList}"
于 2013-10-15T23:53:45.773 回答