【发布时间】:2014-05-02 19:55:37
【问题描述】:
我正在努力将 UserControl(位于 ListBox.ItemTemplate 内)内的按钮绑定到我的 ViewModel。
页面 A 包含以下列表框:
<ListBox x:Name="lbUpcomingBetgames" ItemsSource="{Binding UpcomingBetgames}" Background="{x:Null}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Margin" Value="0,4,0,4"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<customControl:BetgameInfoControl x:Name="upcomingBetgameControl" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的 ViewModel 包含一个我想在我的 CustomControl BetgameInfoControl 中绑定的 RelayCommand:
public RelayCommand BetgameRegisterClicked
{
get;
private set;
}
我的 CustomControl 包含一个按钮:
<Button Grid.Row="0" Content="Accept" Height="50" Command="{Binding Path=Parent.DataContext.BetgameRegisterClicked, ElementName=upcomingBetgameControl}" CommandParameter="{Binding Description}" />
永远不会调用 RelayCommand。我尝试了不同的方法来绑定按钮中的命令属性,但没有任何效果。
有人可以帮帮我吗?
【问题讨论】:
标签: wpf xaml windows-phone-8 mvvm mvvm-light