コード例 #1
0
 internal TemplateBindingExpression(DependencyObject source, TemplateBindingExtension binding, bool runtimeCheck)
 {
     this.Source = source;
     this.sourceProperty = binding.Property;
     this.bindingExtension = binding;
     this.runtimeCheck = runtimeCheck;
 }
コード例 #2
0
        public RadioButtonList()
        {
            Style  style   = new Style(typeof(ListBoxItem));
            Setter setter1 = new Setter(FrameworkElement.MarginProperty, (object)new Thickness(2.0, 2.0, 2.0, 0.0));

            style.Setters.Add((SetterBase)setter1);
            FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(RadioButton));

            frameworkElementFactory.SetValue(UIElement.FocusableProperty, (object)false);
            TemplateBindingExtension bindingExtension = new TemplateBindingExtension(ContentPresenter.ContentProperty);

            frameworkElementFactory.SetValue(ContentControl.ContentProperty, (object)bindingExtension);
            frameworkElementFactory.SetValue(ToggleButton.IsCheckedProperty, (object)new Binding()
            {
                Path           = new PropertyPath("IsSelected", new object[0]),
                RelativeSource = RelativeSource.TemplatedParent,
                Mode           = BindingMode.TwoWay
            });
            frameworkElementFactory.SetValue(UIElement.IsEnabledProperty, (object)new TemplateBindingExtension(UIElement.IsEnabledProperty));
            ControlTemplate controlTemplate = new ControlTemplate();

            controlTemplate.VisualTree = frameworkElementFactory;
            Setter setter2 = new Setter(Control.TemplateProperty, (object)controlTemplate);

            style.Setters.Add((SetterBase)setter2);
            this.Resources.Add((object)typeof(ListBoxItem), (object)style);
        }
コード例 #3
0
 internal TemplateBindingExpression(DependencyObject source, TemplateBindingExtension binding, bool runtimeCheck)
 {
     this.Source           = source;
     this.sourceProperty   = binding.Property;
     this.bindingExtension = binding;
     this.runtimeCheck     = runtimeCheck;
 }
コード例 #4
0
        public void TemplateBindingExtensionConstructor()
        {
            tlog.Debug(tag, $"TemplateBindingExtensionConstructor START");

            TemplateBindingExtension templateBindingExtension = new TemplateBindingExtension();

            tlog.Debug(tag, $"TemplateBindingExtensionConstructor END (OK)");
            Assert.Pass("TemplateBindingExtensionConstructor");
        }
コード例 #5
0
        public void TemplateBindingExtensionConstructor()
        {
            tlog.Debug(tag, $"TemplateBindingExtensionConstructor START");

            TemplateBindingExtension templateBindingExtension = new TemplateBindingExtension();

            Assert.IsNotNull(templateBindingExtension, "null TemplateBindingExtension");
            Assert.IsInstanceOf <TemplateBindingExtension>(templateBindingExtension, "Should return TemplateBindingExtension instance.");

            tlog.Debug(tag, $"TemplateBindingExtensionConstructor END");
        }
コード例 #6
0
        public void TestBorderThickness()
        {
            var element = BorderElement();

            element.BorderThickness(1);

            GetFactoryPropValue(element.Factory, Control.BorderThicknessProperty).Should().BeEquivalentTo(new Thickness(1));

            var binding = new TemplateBindingExtension(Control.BorderThicknessProperty);

            element.BorderThickness(binding);

            GetFactoryPropValue(element.Factory, Control.BorderThicknessProperty).Should().Be(binding);
        }
コード例 #7
0
        public void TestBorderBrush()
        {
            var element = BorderElement();

            element.BorderBrush(Brushes.Red);

            GetFactoryPropValue(element.Factory, Control.BorderBrushProperty).Should().Be(Brushes.Red);

            var binding = new TemplateBindingExtension(Control.BorderBrushProperty);

            element.BorderBrush(binding);

            GetFactoryPropValue(element.Factory, Control.BorderBrushProperty).Should().Be(binding);
        }
コード例 #8
0
        public void TestControlBackground()
        {
            var element = CheckBoxElement();

            element.Background(Brushes.Red);

            GetFactoryPropValue(element.Factory, Control.BackgroundProperty).Should().Be(Brushes.Red);

            var binding = new TemplateBindingExtension(Control.BackgroundProperty);

            element.Background(binding);

            GetFactoryPropValue(element.Factory, Control.BackgroundProperty).Should().Be(binding);
        }
コード例 #9
0
        /// <summary>Sets the value of a dependency property.</summary>
        /// <param name="dp">The dependency property identifier of the property to set.</param>
        /// <param name="value">The new value.</param>
        public void SetValue(DependencyProperty dp, object value)
        {
            if (this.@sealed)
            {
                throw new InvalidOperationException("Can't change FrameworkElementFactory after sealed");
            }
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }
            if (!dp.IsValidValue(value) && !(value is MarkupExtension) && !(value is DeferredReference) && !(value is BindingBase))
            {
                object[] objArray1 = new object[] { value, dp.Name };
                throw new ArgumentException("InvalidPropertyValue");
            }

            /*
             * //if (StyleHelper.IsStylingLogicalTree(dp, value))
             * //{
             * //    throw new NotSupportedException("ModifyingLogicalTreeViaStylesNotImplemented");
             * //}
             */

            if (dp.ReadOnly)
            {
                throw new ArgumentException("ReadOnlyPropertyNotAllowed");
            }
            ResourceReferenceExpression resourceReferenceExpression = value as ResourceReferenceExpression;
            object resourceKey = null;

            if (resourceReferenceExpression != null)
            {
                resourceKey = resourceReferenceExpression.ResourceKey;
            }
            if (resourceKey != null)
            {
                this.UpdatePropertyValueList(dp, PropertyValueType.Resource, resourceKey);
                return;
            }
            TemplateBindingExtension templateBindingExtension = value as TemplateBindingExtension;

            if (templateBindingExtension != null)
            {
                this.UpdatePropertyValueList(dp, PropertyValueType.TemplateBinding, templateBindingExtension);
                return;
            }
            this.UpdatePropertyValueList(dp, PropertyValueType.Set, value);
        }
コード例 #10
0
 public void Destroy()
 {
     t1 = null;
     tlog.Info(tag, "Destroy() is called!");
 }
コード例 #11
0
 public void Init()
 {
     tlog.Info(tag, "Init() is called!");
     t1 = new TemplateBindingExtension();
 }
コード例 #12
0
        public void LabelSet(string name, Label label, double[] p, bool sh) //header要素のコントロールテンプレートおよびプロパティ更新メソッド
        {                                                                   //文字を持っていたり多角形であったりするラベルのコントロールテンプレートを設定する
            //テンプレートの再利用を考えるとポリゴンのポジションは原点を左上に指定し,テンプレート外からマージンにより全体の原点座標を設定する(テンプレート内で座標を設定するとそのテンプレートを利用する全コントロールが同じ位置になってしまう)
            //this.header.Content = windowWidth.ToString(format);//小数第二位まで テスト用
            double contentSize = 1;

            if (label != null)
            {//一部のListBoxのItems(nullを渡している)のフォントサイズはこのメソッドでは指定しない(形状は同じだが文字数が異なるため)
                contentSize = label.Content.ToString().Replace("\n", "").Length;
            }

            ControlTemplate labelTemplate = new ControlTemplate(typeof(Label));

            FrameworkElementFactory gri       = new FrameworkElementFactory(typeof(Grid));
            FrameworkElementFactory pol       = new FrameworkElementFactory(typeof(Polygon)); //ポリゴン用
            FrameworkElementFactory cir       = new FrameworkElementFactory(typeof(Ellipse)); //円用
            FrameworkElementFactory con       = new FrameworkElementFactory(typeof(ContentPresenter));
            FrameworkElementFactory conShadow = new FrameworkElementFactory(typeof(ContentPresenter));

            if (true)//name == "Header" || name == "RankNameLabel" || name == "MemberGroupLabel")//多角形ラベル
            {
                pol = new FrameworkElementFactory(typeof(Polygon));
                TemplateBindingExtension b = new TemplateBindingExtension(Label.BackgroundProperty);
                pol.SetValue(Polygon.FillProperty, b);
                pol.SetValue(Polygon.PointsProperty, PolygonPoints(p));
                if (name == "ParticipantRankLabel")
                {
                    pol.SetValue(Polygon.StrokeProperty, new SolidColorBrush(Color.FromRgb(0, 0, 0)));
                    pol.SetValue(Polygon.PointsProperty, PentaPoints(p));
                }
            }
            else//円形ラベル//現状なし
            {
                cir = new FrameworkElementFactory(typeof(Ellipse));
                TemplateBindingExtension b = new TemplateBindingExtension(Label.BackgroundProperty);
                cir.SetValue(Ellipse.FillProperty, b);
                cir.SetValue(Ellipse.WidthProperty, rowSize * p[2]);
                cir.SetValue(Ellipse.HeightProperty, columnSize * p[3]);
            }

            if (name != "MemberGroupLabel")//name == "Header" || name == "RankNameLabel" || name == "ComaAlgorithmLabel")//文字(コンテンツ)を持つラベル
            {
                con = new FrameworkElementFactory(typeof(ContentPresenter));
                if (name == "ParticipantRankLabel")
                {
                    con.SetValue(ContentPresenter.MarginProperty, MarginCenter(p, 1.1, name));//マージンにより左端中央に配置
                }
                else
                {
                    con.SetValue(ContentPresenter.MarginProperty, MarginLeftCenter(p, contentSize));//マージンにより左端中央に配置
                }

                if (label == null)
                {
                    if (name == "ComaAlgorithmLabel")
                    {                                                                 //ComaAlgorithmLabelのとき
                        con.SetValue(TextBlock.FontSizeProperty, rowSize * p[2] / 4); //[i][コ][マ][目]
                    }
                    else
                    {                                                                   //ParticipantRankLabelのとき
                        con.SetValue(TextBlock.FontSizeProperty, rowSize * p[2] / 1.1); //だいたい1桁
                    }
                }
                else if (name == "AlgorithmLabel" || name == "AlgorithmLabel0" || name == "AlgorithmLabel1" || name == "AlgorithmLabel2")
                {
                    double fontSize = rowSize * p[2] / contentSize * 0.8;
                    if (fontSize > columnSize * p[3])
                    {
                        fontSize = columnSize * p[3];
                    }
                    con.SetValue(TextBlock.FontSizeProperty, fontSize);
                }
                else
                {
                    con.SetValue(TextBlock.FontSizeProperty, columnSize * p[3] * 0.7);//フォントサイズ=ヘッダの縦幅の70%
                }

                conShadow = new FrameworkElementFactory(typeof(ContentPresenter));
                conShadow.SetValue(TextBlock.ForegroundProperty, Brushes.Black);
                conShadow.SetValue(TextBlock.FontSizeProperty, columnSize * p[3] * 0.7);

                conShadow.SetValue(ContentPresenter.MarginProperty, MarginLeftCenterS(p, contentSize));//マージンにより左端中央に配置
            }
            else if (name == "MemberGroupLabel")
            {                                                       //縦書き
                con = new FrameworkElementFactory(typeof(ContentPresenter));
                double fontSize = rowSize * p[2] * 0.7;             //フォントサイズ=横幅の70%
                if (fontSize * contentSize > columnSize * p[3])     //フォントサイズが縦幅を超えたとき
                {
                    fontSize = columnSize * p[3] / contentSize;     //フォントサイズ=縦幅/文字数の70%
                }
                con.SetValue(TextBlock.FontSizeProperty, fontSize); //フォントサイズ=横幅の70%
                con.SetValue(ContentPresenter.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                con.SetValue(ContentPresenter.VerticalAlignmentProperty, VerticalAlignment.Top);
            }

            //Grid構築
            if (sh)//name == "Header")
            {
                gri.AppendChild(pol);
                gri.AppendChild(conShadow);
                gri.AppendChild(con);
            }
            else if (!sh)//name == "RankNameLabel" || name == "MemberGroupLabel")
            {
                gri.AppendChild(pol);
                gri.AppendChild(con);
            }
            else if (false)
            {
                gri.AppendChild(cir);
            }

            //ビジュアルツリーに登録
            labelTemplate.VisualTree = gri;

            //コントロールテンプレート更新
            App.Current.Resources[name] = labelTemplate;

            if (label != null)
            {
                label.IsHitTestVisible = false;                                                                                                                                //マウス判定を消す
                label.Margin           = new Thickness(rowSize * p[0], columnSize * p[1], -windowWidth + rowSize * (p[0] + p[2]), -windowHeight + columnSize * (p[1] + p[3])); //Ellipseに対しては右と下のマージンを削らなくてよい?
            }
        }
コード例 #13
0
        public void EllipseButtonSet(string name, Button button, double[] p, bool sh)//Button要素のコントロールテンプレートおよびプロパティ更新メソッド
        {
            //this.header.Content = windowWidth.ToString(format);//小数第二位まで テスト用
            double contentSize = 1;

            contentSize = button.Content.ToString().Replace("\n", "").Length;

            ControlTemplate buttonTemplate = new ControlTemplate(typeof(Button));

            FrameworkElementFactory gri = new FrameworkElementFactory(typeof(Grid));

            FrameworkElementFactory  el = new FrameworkElementFactory(typeof(Ellipse));
            TemplateBindingExtension b  = new TemplateBindingExtension(Button.BackgroundProperty);

            el.SetValue(Ellipse.FillProperty, b); //pol要素のFillプロパティをbindingでバインドしますの意
            if (name == "GroupNameChangeButton" || name == "GroupOpenButton")
            {                                     //真円
                el.SetValue(Ellipse.StrokeProperty, Brushes.Black);
                if (rowSize > columnSize)
                {
                    el.SetValue(Ellipse.WidthProperty, columnSize * p[2]);
                    el.SetValue(Ellipse.HeightProperty, columnSize * p[3]);
                }
                else
                {
                    el.SetValue(Ellipse.WidthProperty, rowSize * p[2]);
                    el.SetValue(Ellipse.HeightProperty, rowSize * p[3]);
                }
            }
            else
            {
                el.SetValue(Ellipse.WidthProperty, rowSize * p[2]);
                el.SetValue(Ellipse.HeightProperty, columnSize * p[3]);
            }
            el.SetValue(Ellipse.HorizontalAlignmentProperty, HorizontalAlignment.Left);
            el.SetValue(Ellipse.VerticalAlignmentProperty, VerticalAlignment.Top);
            el.SetValue(Ellipse.CursorProperty, Cursors.Hand);
            //pol.SetValue(Polygon.NameProperty, "memberPolygon");//何故かセットされない

            FrameworkElementFactory con       = new FrameworkElementFactory(typeof(ContentPresenter));
            FrameworkElementFactory conShadow = new FrameworkElementFactory(typeof(ContentPresenter));

            con.SetValue(ContentPresenter.IsHitTestVisibleProperty, false);//テキストにはマウス判定を持たせない
            if (name == "GroupNameChangeButton" || name == "GroupOpenButton")
            {
                con.SetValue(ContentPresenter.MarginProperty, CircleMarginCenter(p, contentSize, name));
            }
            else
            {
                con.SetValue(ContentPresenter.MarginProperty, MarginCenter(p, contentSize, name));
            }

            if (sh)
            {
                gri.AppendChild(el);
                gri.AppendChild(con);
            }
            else
            {
                gri.AppendChild(el);
                gri.AppendChild(con);
            }


            //pol.Name = "buttonPolygon";//この方法だとセットされる
            buttonTemplate.VisualTree = gri;

            App.Current.Resources[name] = buttonTemplate;//コントロールテンプレート更新
            button.Margin = new Thickness(rowSize * p[0], columnSize * p[1], 0, 0);
            if (name == "GroupNameChangeButton" || name == "GroupOpenButton")
            {
                if (rowSize > columnSize)
                {
                    button.FontSize = columnSize * p[2] * 1.0 / contentSize * 0.8;//フォントサイズ=80% * ボタンの縦幅/文字数
                }
                else
                {
                    button.FontSize = rowSize * p[2] * 1.0 / contentSize * 0.8;//フォントサイズ=80% * ボタンの横幅/文字数
                }
            }
            else
            {
                button.FontSize = rowSize * p[2] * 1.0 / contentSize * 0.8;//フォントサイズ=80% * ボタンの横幅/文字数
            }
        }
コード例 #14
0
        public void PolygonButtonSet(string name, Button button, double[] p, bool sh)//Button要素のコントロールテンプレートおよびプロパティ更新メソッド
        {
            //this.header.Content = windowWidth.ToString(format);//小数第二位まで テスト用
            double contentSize = 1;

            if (button != null)
            {//ListBoxのItems(nullを渡している)のフォントサイズはこのメソッドでは指定しない
                contentSize = button.Content.ToString().Replace("\n", "").Length;
            }

            double angle;

            if (name == "MemberButton")
            {
                angle = 5;
            }
            else if (name == "MatchingButton")
            {
                angle = -4;//だいたい文字数の逆比
            }
            else
            {
                angle = 0;
            }

            //Style buttonStyle = new Style(typeof(Button));
            ControlTemplate buttonTemplate = new ControlTemplate(typeof(Button));

            RotateTransform rotateTransform1 = new RotateTransform(angle);

            rotateTransform1.CenterX = (p[0] + (p[0] + p[2])) / 2.0;
            rotateTransform1.CenterY = (p[1] + (p[1] + p[3])) / 2.0;

            FrameworkElementFactory gri = new FrameworkElementFactory(typeof(Grid));

            FrameworkElementFactory  pol = new FrameworkElementFactory(typeof(Polygon));
            TemplateBindingExtension b   = new TemplateBindingExtension(Button.BackgroundProperty);

            pol.SetValue(Polygon.FillProperty, b);//pol要素のFillプロパティをbindingでバインドしますの意
            pol.SetValue(Polygon.PointsProperty, PolygonPoints(p));
            pol.SetValue(Polygon.CursorProperty, Cursors.Hand);
            if (name == "MemberNameButton" || name == "MemberDeleteButton" || name == "ParticipantMemberButton" || name == "ComaAlgorithmButton0" || name == "ComaAlgorithmButton1" || name == "ComaAlgorithmButton2")
            {//ListBoxでボタンを横に配置するため
                pol.SetValue(ContentPresenter.MarginProperty, new Thickness(rowSize * p[0], 0, 0, 0));
            }
            //pol.SetValue(Polygon.NameProperty, "memberPolygon");//何故かこの方法ではNameはセットされない
            if (!sh) /*button == null || name == "GroupAddButton" || name == "GroupDeleteButton"
                     || name == "MemberAddButton" || name=="TableButton" || name == "ComaButton"
                     || name == "ComaAlgorithm0" || name == "ComaAlgorithm1" || name == "ComaAlgorithm2" || name == "ParticipantMemberButton")//!shadowでも可?*/
            {        //ボタンの枠線表示する
                pol.SetValue(Polygon.StrokeProperty, Brushes.Black);
                //pol.SetValue(Polygon.StrokeThicknessProperty, Shape.StrokeThickness(1));
            }

            FrameworkElementFactory con       = new FrameworkElementFactory(typeof(ContentPresenter));
            FrameworkElementFactory conShadow = new FrameworkElementFactory(typeof(ContentPresenter));

            if (button == null)
            {                                                                   //ListBoxItems
                con.SetValue(ContentPresenter.IsHitTestVisibleProperty, false); //テキストにはマウス判定を持たせない
                con.SetValue(ContentPresenter.VerticalAlignmentProperty, VerticalAlignment.Center);
                if (name == "MemberNameButton" || name == "MemberDeleteButton" || name == "ParticipantMemberButton" || name == "ComaAlgorithmButton0" || name == "ComaAlgorithmButton1" || name == "ComaAlgorithmButton2")
                {//ListBoxでボタンを横に配置するため
                    con.SetValue(ContentPresenter.MarginProperty, new Thickness(rowSize * (0.2 + p[0]), 0, 0, 0));
                }
                else if (name == "MemberRankButton")
                {
                    con.SetValue(ContentPresenter.MarginProperty, new Thickness(rowSize * 0.2, 0, 0, 0));
                }
                else
                {
                    con.SetValue(ContentPresenter.MarginProperty, new Thickness(rowSize * 1, 0, 0, 0));
                }
            }
            else if (name == "GroupAddButton" || name == "GroupDeleteButton" || name == "MemberAddButton")
            {                                                                                              //縦書きなので別処理,かつ,影をもたせない
                con.SetValue(ContentPresenter.MarginProperty, PortrateMarginCenter(p, contentSize, name)); //マージンにより左端中央に配置
                con.SetValue(ContentPresenter.RenderTransformProperty, rotateTransform1);
                con.SetValue(ContentPresenter.IsHitTestVisibleProperty, false);                            //テキストにはマウス判定を持たせない
            }
            else if (name == "ToMenuButton" || name == "NextButton")
            {
                //縦書きなので別処理
                con.SetValue(ContentPresenter.MarginProperty, PortrateMarginCenter(p, contentSize, name)); //マージンにより左端中央に配置
                con.SetValue(ContentPresenter.RenderTransformProperty, rotateTransform1);
                con.SetValue(ContentPresenter.IsHitTestVisibleProperty, false);                            //テキストにはマウス判定を持たせない

                conShadow.SetValue(TextBlock.ForegroundProperty, Brushes.Black);
                conShadow.SetValue(ContentPresenter.MarginProperty, PortrateMarginCenterS(p, contentSize)); //マージンにより左端中央に配置
                conShadow.SetValue(ContentPresenter.RenderTransformProperty, rotateTransform1);
                conShadow.SetValue(ContentPresenter.IsHitTestVisibleProperty, false);                       //テキストにはマウス判定を持たせない
            }
            else
            {
                Thickness c;
                Thickness s;
                if (name == "ConfigButton")
                {
                    c = MarginLeftCenter(p, contentSize);
                    s = MarginLeftCenterS(p, contentSize);
                }
                else
                {
                    c = MarginCenter(p, contentSize, name);
                    s = MarginCenterS(p, contentSize, name);
                }
                con.SetValue(ContentPresenter.MarginProperty, c);               //マージンにより左端中央に配置
                con.SetValue(ContentPresenter.RenderTransformProperty, rotateTransform1);
                con.SetValue(ContentPresenter.IsHitTestVisibleProperty, false); //テキストにはマウス判定を持たせない

                conShadow.SetValue(TextBlock.ForegroundProperty, Brushes.Black);
                conShadow.SetValue(ContentPresenter.MarginProperty, s);               //マージンにより左端中央に配置
                conShadow.SetValue(ContentPresenter.RenderTransformProperty, rotateTransform1);
                conShadow.SetValue(ContentPresenter.IsHitTestVisibleProperty, false); //テキストにはマウス判定を持たせない
            }
            if (sh)
            {
                gri.AppendChild(pol);
                gri.AppendChild(conShadow);
                gri.AppendChild(con);
            }
            else
            {
                gri.AppendChild(pol);
                gri.AppendChild(con);
            }

            //pol.Name = "buttonPolygon";//この方法だとNameはセットされる
            buttonTemplate.VisualTree = gri;

            //Setter buttonTemplateSetter = new Setter(TemplateProperty, buttonTemplate);
            //buttonStyle.Setters.Add(buttonTemplateSetter);

            App.Current.Resources[name] = buttonTemplate;//コントロールテンプレート更新

            if (button != null)
            {//ListBoxのItemsに関してはフォントサイズを各自で設定する(全てのItemが同じテンプレートを参照するため)
                //が,MemberButtonsのNameボタンに関してはRankボタンの横に配置するためにマージンを設定する
                button.Margin = new Thickness(rowSize * p[0], columnSize * p[1], 0, 0);
                if (name == "ToMenuButton" || name == "NextButton")                // || name == "GroupAddButton" || name == "GroupDeleteButton" || name == "MemberAddButton")
                {                                                                  //縦書き
                    button.FontSize = columnSize * p[3] * 1.0 / contentSize * 0.3; //フォントサイズ=80% * ボタンの縦幅/文字数
                }
                else if (name == "GroupDeleteButton" || name == "GroupAddButton" || name == "MemberAddButton")
                {                                                                  //縦書き(文字数の関係でボタンによって比率を変えている)
                    button.FontSize = columnSize * p[3] * 1.0 / contentSize * 0.4; //フォントサイズ=80% * ボタンの縦幅/文字数
                }
                else
                {
                    double fontSize = rowSize * p[2] * 1.0 / contentSize * 0.8;
                    if (fontSize > columnSize * p[3] * 0.8)
                    {//縦幅を超えてしまわないように
                        fontSize = columnSize * p[3] * 0.8;
                    }
                    button.FontSize = fontSize;//フォントサイズ=80% * ボタンの横幅/文字数
                }
            }
        }
コード例 #15
0
 public void Destroy()
 {
     tExtension = null;
     tlog.Info(tag, "Destroy() is called!");
 }
コード例 #16
0
ファイル: Baml2006Reader.cs プロジェクト: sjyanxin/WPFSource
        // (property, markup extension, value) including the well known WPF TemplateBinding, StaticResource or DynamicResource markup extensions
        // Writes out a property with a markup extension.  However, if there is a x:Static, Type, or TemplateBinding inside the ME, we code that
        // specially.  e.g. Property="{FooExtension {x:Static f:Foo.Bar}}" would be written out as one Baml Record
        private void Process_PropertyWithExtension() 
        {
            Common_Process_Property(); 
 
            short propertyId = _binaryReader.ReadInt16();
            Int16 extensionId = _binaryReader.ReadInt16(); 
            Int16 valueId = _binaryReader.ReadInt16();


            XamlMember property = GetProperty(propertyId, _context.CurrentFrame.XamlType); 
            Int16 extensionTypeId = (Int16)(extensionId & ExtensionIdMask);
            XamlType extensionType = BamlSchemaContext.GetXamlType((short)(-extensionTypeId)); 
 
            bool isValueTypeExtension = (extensionId & TypeExtensionValueMask) == TypeExtensionValueMask;
            bool isValueStaticExtension = (extensionId & StaticExtensionValueMask) == StaticExtensionValueMask; 

            Type typeExtensionType = null;
            Type memberType = null;
            object value = null; 

 
            // Write out the main Extension {FooExtension 
            _xamlNodesWriter.WriteStartMember(property);
 
            // If we're in the binary case, we try to write the value out directly
            bool handled = false;
            if (_isBinaryProvider)
            { 
                object param = null;
                object providedValue = null; 
 
                if (isValueStaticExtension)
                { 
                    Type ownerType = null;
                    string staticExParam = GetStaticExtensionValue(valueId, out ownerType, out providedValue);

                    // If it's a Known command or a SystemResourceKey, send the value across directly 
                    if (providedValue != null)
                    { 
                        param = providedValue; 
                    }
                    else 
                    {
                        System.Windows.Markup.StaticExtension staticExtension =
                            new System.Windows.Markup.StaticExtension(staticExParam);
                        Debug.Assert(ownerType != null); 
                        staticExtension.MemberType = ownerType;
                        param = staticExtension.ProvideValue(null); // if MemberType is set we don't need ITypeResolver 
                    } 
                }
                else if (isValueTypeExtension) 
                {
                    param = BamlSchemaContext.GetXamlType(valueId).UnderlyingType;
                }
                else 
                {
                    // For all other scenarios, we want to just write out the type 
 
                    if (extensionTypeId == Baml2006SchemaContext.TemplateBindingTypeId)
                    { 
                        param = _context.SchemaContext.GetDependencyProperty(valueId);
                    }
                    else if (extensionTypeId == Baml2006SchemaContext.StaticExtensionTypeId)
                    { 
                        param = GetStaticExtensionValue(valueId, out memberType, out providedValue);
                    } 
                    else if (extensionTypeId == Baml2006SchemaContext.TypeExtensionTypeId) 
                    {
                        param = BamlSchemaContext.GetXamlType(valueId).UnderlyingType; 
                    }
                    else
                    {
                        param = BamlSchemaContext.GetString(valueId); 
                    }
                } 
 
                // Doing == comparison since we only know how to create those quickly here
                if (extensionTypeId == Baml2006SchemaContext.DynamicResourceTypeId) 
                {
                    value = new DynamicResourceExtension(param);
                    handled = true;
                } 
                else if (extensionTypeId == Baml2006SchemaContext.StaticResourceTypeId)
                { 
                    value = new StaticResourceExtension(param); 
                    handled = true;
                } 
                else if (extensionTypeId == Baml2006SchemaContext.TemplateBindingTypeId)
                {
                    value = new TemplateBindingExtension((DependencyProperty)param);
                    handled = true; 
                }
                else if (extensionTypeId == Baml2006SchemaContext.TypeExtensionTypeId) 
                { 
                    value = param;
                    handled = true; 
                }
                else if (extensionTypeId == Baml2006SchemaContext.StaticExtensionTypeId)
                {
                    if (providedValue != null) 
                    {
                        value = providedValue; 
                    } 
                    else
                    { 
                        System.Windows.Markup.StaticExtension staticExtension = new System.Windows.Markup.StaticExtension((string)param);
                        staticExtension.MemberType = memberType;
                        value = staticExtension;
                    } 
                    handled = true;
                } 
 
                if (handled)
                { 
                    _xamlNodesWriter.WriteValue(value);
                    _xamlNodesWriter.WriteEndMember();

                    return; 
                }
            } 
 
            if (!handled)
            { 

                _xamlNodesWriter.WriteStartObject(extensionType);
                _xamlNodesWriter.WriteStartMember(XamlLanguage.PositionalParameters);
 
                if (isValueStaticExtension)
                { 
 
                    Type ownerType = null;
                    object providedValue; 
                    value = GetStaticExtensionValue(valueId, out ownerType, out providedValue);

                    // If it's a Known command or a SystemResourceKey, send the value across directly
                    if (providedValue != null) 
                    {
                        _xamlNodesWriter.WriteValue(providedValue); 
                    } 
                    else
                    { 
                        // Special case for {x:Static ...} inside the main extension
                        _xamlNodesWriter.WriteStartObject(XamlLanguage.Static);
                        _xamlNodesWriter.WriteStartMember(XamlLanguage.PositionalParameters);
                        _xamlNodesWriter.WriteValue(value); 
                        _xamlNodesWriter.WriteEndMember();
 
                        // In BAML scenario, we want to pass MemberType directly along cuz it's optimal 
                        if (ownerType != null)
                        { 
                            _xamlNodesWriter.WriteStartMember(BamlSchemaContext.StaticExtensionMemberTypeProperty);
                            _xamlNodesWriter.WriteValue(ownerType);
                            _xamlNodesWriter.WriteEndMember();
                        } 
                        _xamlNodesWriter.WriteEndObject();
                    } 
                } 
                else if (isValueTypeExtension)
                { 
                    // Special case for {x:Type ...} inside the main extension
                    _xamlNodesWriter.WriteStartObject(XamlLanguage.Type);
                    _xamlNodesWriter.WriteStartMember(BamlSchemaContext.TypeExtensionTypeProperty);
 
                    typeExtensionType = BamlSchemaContext.GetXamlType(valueId).UnderlyingType;
                    if (_isBinaryProvider) 
                    { 
                        _xamlNodesWriter.WriteValue(typeExtensionType);
                    } 
                    else
                    {
                        _xamlNodesWriter.WriteValue(Logic_GetFullyQualifiedNameForType(BamlSchemaContext.GetXamlType(valueId)));
                    } 
                    _xamlNodesWriter.WriteEndMember();
                    _xamlNodesWriter.WriteEndObject(); 
                } 
                else
                { 
                    // For all other scenarios, we want to just write out the type

                    if (extensionTypeId == Baml2006SchemaContext.TemplateBindingTypeId)
                    { 
                        if (this._isBinaryProvider)
                        { 
                            value = BitConverter.GetBytes(valueId); 
                        }
                        else 
                        {
                            value = Logic_GetFullyQualifiedNameForMember(valueId);
                        }
                    } 
                    else if (extensionTypeId == Baml2006SchemaContext.StaticExtensionTypeId)
                    { 
                        // If we're here, that means we're not a binary provider which means we can't 
                        // support writing the provided value out directly.
                        object providedValue; 
                        value = GetStaticExtensionValue(valueId, out memberType, out providedValue);
                    }
                    else if (extensionTypeId == Baml2006SchemaContext.TypeExtensionTypeId)
                    { 
                        value = BamlSchemaContext.GetXamlType(valueId).UnderlyingType;
                    } 
                    else 
                    {
                        value = BamlSchemaContext.GetString(valueId); 
                    }

                    _xamlNodesWriter.WriteValue(value);
                } 

                _xamlNodesWriter.WriteEndMember(); 
                if (memberType != null) 
                {
                    _xamlNodesWriter.WriteStartMember(BamlSchemaContext.StaticExtensionMemberTypeProperty); 
                    _xamlNodesWriter.WriteValue(memberType);
                    _xamlNodesWriter.WriteEndMember();
                }
            } 
            _xamlNodesWriter.WriteEndObject();
            _xamlNodesWriter.WriteEndMember(); 
        }