Esempio n. 1
0
        public AnimationsDemoPage()
        {
            InitializeComponent();

            _groups = new ResetableCollection <RecipeGroup>(Enumerable.Range(0, 10).Select(j =>
                                                                                           new RecipeGroup(
                                                                                               Enumerable.Range(0, _rnd.Next(5, 16)).Select(k => CreateRecipe(j, k)))
            {
                Name = "Group #" + j
            }));

            _dataSource = new DelegatingItemsSource(_groups);

            Func <DelegatingItemsSource, int, string> KeyFromIndexFunc = (ds, index) => ds.GetAt(index).ToString();

            repeater.ItemsSource         = _dataSource;
            _dataSource.KeyFromIndexFunc = KeyFromIndexFunc;

            repeater.Layout = new StackLayout();
            var generator = new AnimationElementFactory(
                (DataTemplate)Resources["RecipeGroupTemplate"],
                (DataTemplate)Resources["RecipeTemplate"],
                (ElementAnimator)Resources["SharedAnimator"],
                KeyFromIndexFunc);

#if BUILD_WINDOWS
            repeater.ItemTemplate = (Windows.UI.Xaml.IElementFactory)generator;
#else
            repeater.ItemTemplate = generator;
#endif

            goBack.Click += delegate { Frame.GoBack(); };

            commands.KeyDown += (s, e) =>
            {
                if (e.Key == Windows.System.VirtualKey.Enter)
                {
                    e.Handled = true;
                    ProcessCommands(commands.Text.ToLowerInvariant());
                }
            };

            stackLayout.Checked     += delegate { generator.IsInnerLayoutGrid = false; };
            gridLayout.Checked      += delegate { generator.IsInnerLayoutGrid = true; };
            withUniqueId.Checked    += delegate { generator.UpdateInnerLayouts(); };
            withoutUniqueId.Checked += delegate { generator.UpdateInnerLayouts(); };

            animationSlowdown.ValueChanged += delegate
            {
                //ElementAnimator.AnimationSlowdownFactor = animationSlowdown.Value;
            };
        }
Esempio n. 2
0
            protected override UIElement GetElementCore(ElementFactoryGetArgs args)
#endif
            {
                var key     = (args.Data is RecipeGroup) ? "Group" : "Recipe";
                var element = (FrameworkElement)_recyclePool.TryGetElement(key, args.Parent);

                if (element == null)
                {
                    if (args.Data is RecipeGroup)
                    {
                        element = (FrameworkElement)_groupTemplate.LoadContent();
                        _innerRepeaters.Add((ItemsRepeater)element.FindName("groupLayout"));
                    }
                    else
                    {
                        element = (FrameworkElement)_recipeTemplate.LoadContent();
                    }
                }

                element.Tag = key;

                if (args.Data is RecipeGroup)
                {
                    var group     = (RecipeGroup)args.Data;
                    var groupName = (TextBlock)element.FindName("groupName");
                    var repeater  = (ItemsRepeater)element.FindName("groupLayout");

                    groupName.Text = group.Name;
                    var dataSource = new DelegatingItemsSource(group);
                    dataSource.KeyFromIndexFunc = _KeyFromIndexFunc;
                    repeater.ItemsSource        = dataSource;
                    repeater.Layout             = IsInnerLayoutGrid ? (VirtualizingLayout) new UniformGridLayout()
                    {
                        MinItemWidth = 150, MinItemHeight = 150
                    } : (VirtualizingLayout) new StackLayout();
                    RepeaterTestHooks.SetLayoutId(repeater.Layout, group.Name);
                    repeater.ItemTemplate = this;
                    repeater.Animator     = _animator;
                }
                else
                {
                    var recipe      = (Recipe)args.Data;
                    var image       = (Image)element.FindName("recipeImage");
                    var description = (TextBlock)element.FindName("recipeDescription");

                    image.Source     = new BitmapImage(recipe.ImageUri);
                    description.Text = recipe.Description;
                }

                return(element);
            }