【问题标题】:Windows Phone and Silverlight ListBox.ItemTemplateWindows Phone 和 Silverlight ListBox.ItemTemplate
【发布时间】:2011-01-04 22:15:43
【问题描述】:

我有一个带有以下列表框的 Windows Phone 7 应用程序,每个项目都包含 2 个文本块和一个 HyperlinkBut​​ton。

 <ListBox.ItemTemplate><DataTemplate><StackPanel Orientation="Vertical">
                            <TextBlock/>
                            <TextBlock/>
                            <HyperlinkButton Content="[More...]" FontSize="12"HorizontalAlignment="Right" Height="30" Click="ClickEvent">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click"<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding GetCommand, Mode=OneWay}"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </HyperlinkButton>
                        </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>

在 ViewModel 构造函数中,我有以下代码:

GetCommand = new RelayCommand(() =>{some code}); where GetCommand is a property :

public RelayCommand GetCommand { get; private set; }

我的问题是当我按下按钮时GetCommand = new RelayCommand(() =&gt;{some code}); 没有执行。

我必须说,如果不将 HyperlinkBut​​ton 放置在 itemTemplate 中,一切正常。 我使用 Galasoft mvvm light takeit - http://www.galasoft.ch/mvvm/getstarted/ 感谢您的帮助。

【问题讨论】:

  • 请不要在这么快的接班人中问类似的问题。只需用额外的细节编辑您的原始问题。考虑删除相同主题的其他问题

标签: silverlight windows-phone-7 listbox windows-phone itemtemplate


【解决方案1】:

我猜你的 XAML 中有错字,应该是 -

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Click">
        <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding GetCommand, Mode=OneWay}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

从绑定表达式中删除 Mode=OneWay 后尝试代码。

HTH,indyfromoz

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2010-09-26
    • 1970-01-01
    相关资源
    最近更新 更多