3,034 questions
Hello
Welcome to Microsoft Q&A,
How to get PivotItem from Button placed on PivotItemHeader
For this scenario, we suggest you use xaml binding to approach. If you want to remove item, you just need to process the data source, but not get the real control. Please refer following code.
public sealed partial class MainPage : Page
{
public ObservableCollection<string> Items = new ObservableCollection<string>() {"One","Two","Three","Four" };
public MainPage()
{
this.InitializeComponent();
this.DataContext = this;
MyPivot.ItemsSource = Items;
}
public ICommand ItemCommand
{
get
{
return new CommadEventHandler<string>((item) => ItemClick(item));
}
}
private void ItemClick(string item)
{
Items.Remove(item);
}
}
class CommadEventHandler<T> : ICommand
{
public event EventHandler CanExecuteChanged;
public Action<T> action;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
this.action((T)parameter);
}
public CommadEventHandler(Action<T> action)
{
this.action = action;
}
}
Xaml
I have make sample here.
Thanks
Nico Zhu