I registered a SizeChangedHandler on my ScatterViewItem:
private void MethodBoxScatterSizeChanged(object sender, SizeChangedEventArgs args)
{
if (args.NewSize.Width < 150 && args.NewSize.Height < 150)
{
ScatterViewItem svi = sender as ScatterViewItem;
TextBox txt = new TextBox();
txt.Text = "Test";
txt.Tag = svi.Content;
svi.Content = txt;
args.Handled = true;
}
else if (args.PreviousSize.Width < 150 && args.PreviousSize.Height < 150 && args.NewSize.Height > 150 && args.NewSize.Width > 150)
{
ScatterViewItem svi = sender as ScatterViewItem;
FrameworkElement old = (svi.Content as FrameworkElement).Tag as FrameworkElement;
svi.Content = old;
args.Handled = true;
}
}
As you can see, I want to set Test as the content of the ScatterViewItem if it is small, and the original content if it is bigger again. But once I decreased it, it always stays the Test way. What am I doing wrong?
in the if statement, you aren't checking whether you've already switched to "Test". so if you get two events saying it has resized to be smaller than 150x150, content.Tag ends up being set to "Test" which is what you pull from when resized back to > 150x150