コード例 #1
0
        /// <summary>
        /// Main flow of the render pipeline.
        /// </summary>
        /// <param name="sc"></param>
        /// <param name="ist"></param>
        /// <param name="recycler"></param>
        void ElementPipeline(SelectorContext sc, ItemState ist, Recycler <FrameworkElement, ItemState> recycler)
        {
            sc.SetTick(ist.index);
            var createit = true;

            if (LabelSelector != null)
            {
                var ox = LabelSelector.Convert(sc, typeof(bool), null, System.Globalization.CultureInfo.CurrentUICulture.Name);
                if (ox is bool bx)
                {
                    createit = bx;
                }
                else
                {
                    createit = ox != null;
                }
            }
            if (!createit)
            {
                return;
            }
            var current = recycler.Next(ist);

            if (current == null)
            {
                return;
            }
            if (!current.Item1)
            {
                // recycled: restore binding if we are using a LabelFormatter
                if (LabelFormatter != null && LabelStyle != null)
                {
                    BindTo(this, nameof(LabelStyle), current.Item2, FrameworkElement.StyleProperty);
                }
            }
            // default text
            var text = ist.label == null
                                ? String.Empty
                                : (String.IsNullOrEmpty(LabelFormatString)
                                        ? ist.label.ToString()
                                        : String.Format(LabelFormatString, ist.label)
                                   );

            if (LabelFormatter != null)
            {
                // call for Style, String override
                var format = LabelFormatter.Convert(sc, typeof(Tuple <Style, String>), null, System.Globalization.CultureInfo.CurrentUICulture.Name);
                if (format is Tuple <Style, String> ovx)
                {
                    if (ovx.Item1 != null)
                    {
                        current.Item2.Style = ovx.Item1;
                    }
                    if (ovx.Item2 != null)
                    {
                        text = ovx.Item2;
                    }
                }
            }
            // back-fill values
            var shim = new TextShim()
            {
                Text = text
            };

            current.Item2.DataContext = shim;
            BindTo(shim, nameof(Visibility), current.Item2, UIElement.VisibilityProperty);
            ist.element = current.Item2;
            sc.Generated(ist);
        }