Xaml Pivot SelectedItem属性

Xaml Pivot SelectedItem属性,xaml,windows-phone-8,Xaml,Windows Phone 8,我想查找当前显示的是哪个数据透视项,但在CommandParameter中总是收到null。代码如下: xaml <Pivot ItemsSource="{Binding Categories}" x:Name="MainList"> ... </Pivot> ... <Page.BottomAppBar> <CommandBar> <AppBarButton Label="add item" Icon="

我想查找当前显示的是哪个数据透视项,但在
CommandParameter
中总是收到null。代码如下:

xaml

<Pivot ItemsSource="{Binding Categories}" x:Name="MainList">
    ...
</Pivot>

...

<Page.BottomAppBar>
    <CommandBar>
        <AppBarButton Label="add item" Icon="Add" Command="{Binding AddElementCommand}" CommandParameter="{Binding ElementName=MainList, Path=SelectedItem}" />            
    </CommandBar>
</Page.BottomAppBar>
我100%确信DelegateCommand实现正在工作,因为如果我输入
CommandParameter
value
{Binding}
,那么我将收到
AddElement
的参数current ViewModel对象


为什么通过
ElementName
绑定不起作用?是否可以绑定Pivot的SelectedItem?

是的,您可以使用
SelectChanged
事件在
Pivot
控件中获取当前的
PivotItem

这可以帮助您:


是的,但我希望使用MVVM模式,如果可能的话,不要使用行为。此外,我正在为WindowsPhone8.1(XAML)开发。
public DelegateCommand<object> AddElementCommand { get; set; }

public void Init()
{
    this.AddElementCommand = new DelegateCommand<object>(this.AddElement);
}

private void AddElement(object category)
{
     ...
}