0
我想要找到哪個PivotItem當前正在顯示,但總是我在CommandParameter
中收到空值。下面的代碼:Pivot SelectedItem屬性
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
的當前ViewModel對象的參數。
爲什麼通過ElementName
綁定不起作用?是否可以綁定樞軸的SelectedItem?
是的,但我想使用MVVM模式和不使用的行爲,如果有可能。另外,我正在開發Windows Phone 8.1(XAML)。 – Fka 2014-11-13 14:12:30