一个ScatterViewItem取决于大小设定内容

一个ScatterViewItem取决于大小设定内容

本文介绍了一个ScatterViewItem取决于大小设定内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册了一个SizeChangedHandler我ScatterViewItem:

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;
            }
        }

正如你所看到的,我想设置测试为ScatterViewItem的内容,如果是小的,和原来的内容,如果它是更大了。但是,一旦我降低它,它总是停留在测试方式。我究竟做错了什么?

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?

推荐答案

if语句,你不检查您是否已经切换到测试。因此,如果你得到两个事件,称它调整到比150×150小,content.Tag最终被设置为测试,这是你从调整回来时拉> 150×150

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

这篇关于一个ScatterViewItem取决于大小设定内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:04