Windows Phone 和 Silverlight ListBox.ItemTemplate

发布于 2024-10-10 05:35:30 字数 1480 浏览 0 评论 0原文

我有一个带有以下列表框的 Windows Phone 7 应用程序,每个项目都包含 2 个文本块和一个超链接按钮。

 <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(() =>{some code}); 没有执行。

我必须说,如果不将 HyperlinkBut​​ton 放置在 itemTemplate 中,则一切正常。 我使用 Galasoft mvvm light takeit - http://www.galasoft.ch/mvvm/getstarted/< /a> 我很感激任何帮助。

I have a Windows Phone 7 application with the following listbox and every item contains 2 textblocks and a HyperlinkButton.

 <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>

In the ViewModel constructor I have the following code:

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

public RelayCommand GetCommand { get; private set; }

My problem is that GetCommand = new RelayCommand(() =>{some code}); is not executing when I press the button.

I must say that if dont place the HyperlinkButton insise the itemTemplate, everything works fine.
I use the Galasoft mvvm light tookit - http://www.galasoft.ch/mvvm/getstarted/
I appreciate any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度℉ 2024-10-17 05:35:30

我猜您的 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

I am guessing you have a typo in your XAML, it should read -

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

Try the code after removing the Mode=OneWay from the binding expression.

HTH, indyfromoz

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文