我想找出当前显示的是哪个PivotItem,但在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>C#
public DelegateCommand<object> AddElementCommand { get; set; }
public void Init()
{
this.AddElementCommand = new DelegateCommand<object>(this.AddElement);
}
private void AddElement(object category)
{
...
}我100%确定,DelegateCommand实现正在工作,因为如果我放入CommandParameter值{Binding},那么我就会收到AddElement的参数current ViewModel object。
为什么通过ElementName绑定不起作用?是否可以绑定透视的SelectedItem?
发布于 2014-10-12 23:40:57
是的,您可以简单地使用SelctionChanged事件获取Pivot控件中的当前PivotItem。
这可能会对你有所帮助:
https://stackoverflow.com/questions/26318934
复制相似问题