c# - 我的命令绑定(bind)不起作用 - MVVM/DataTemplate

标签 c# data-binding mvvm windows-phone-8 command

我正在尝试绑定(bind)到 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}"

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

最佳答案

您可以绑定(bind)回 LongListSelector使用 ElementName ,以及 DataContext因为那应该是你的ViewModel

Command="{Binding Path=DataContext.LoadSpacesCommand, ElementName=OrganisationList}"

关于c# - 我的命令绑定(bind)不起作用 - MVVM/DataTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19393040/

相关文章:

c# - 使用 Bot Framework C# v4 的动态提示

c# - 如何防止 CurrencyManager 为绑定(bind)对象调用 BeginEdit()/EndEdit() 方法

wpf - 有什么方法可以暂时分离 WPF 中的绑定(bind)吗?

c# - 将 DataRow 绑定(bind)到 TextBox

android - fragment 的 View 模型而不是访问 Activity View 模型?

java - 将Python语法中的ANTLR4嵌入java转换为C#

c# - 无效的跨线程访问问题

c# - 如何在 C# 中找到两个 DateTime 之间的正差

.net - 来自 SplitButton DropDownContent 的绑定(bind)命令不起作用

wpf - MVVMLight ViewModelLocator 注册数据服务