コード例 #1
0
        public void AddUnit(int number)
        {
            if (number <= 0)
            {
                return;
            }

            int    count     = btnlUnits.Count;
            string strFormat = "Unit {0}";

            for (int i = 0; i < number; ++i)
            {
                HighlightButton btnUnit = new HighlightButton();

                btnUnit.button.Content = string.Format(strFormat, count + 1);

                btnUnit.button.GroupName = "UnitControlGroup";

                btnUnit.Name        = string.Format("btnUnit_{0}", count + 1);
                btnUnit.button.Name = string.Format("btnUnit_{0}", count + 1);
                btnUnit.button.Tag  = (int)(count + 1);

                Binding binding = new Binding();
                //binding.BindsDirectlyToSource = true;
                binding.Mode   = BindingMode.OneWay;
                binding.Path   = new PropertyPath("FontSize");
                binding.Source = this.LayoutRoot;


                btnUnit.button.SetBinding(HighlightButton.FontSizeProperty, binding);
                //btnUnit.SetBinding(HighlightButton.FontSizeProperty, binding);

                btnUnit.button.Click += new RoutedEventHandler(UnitButtonControl_Click);

                btnlUnits.Add(btnUnit);

                stpPanel.Children.Add(btnUnit);

                ++count;
            }

            double d = LayoutRoot.FontSize;
        }
コード例 #2
0
        public void AddUnit(int number)
        {
            if (number <= 0)
                return;

            int count = btnlUnits.Count;
            string strFormat = "Unit {0}";

            for (int i = 0; i < number; ++i)
            {
                HighlightButton btnUnit = new HighlightButton();

                btnUnit.button.Content = string.Format(strFormat, count + 1);

                btnUnit.button.GroupName = "UnitControlGroup";

                btnUnit.Name = string.Format("btnUnit_{0}", count + 1);
                btnUnit.button.Name = string.Format("btnUnit_{0}", count + 1);
                btnUnit.button.Tag = (int)(count + 1);

                Binding binding = new Binding();
                //binding.BindsDirectlyToSource = true;
                binding.Mode = BindingMode.OneWay;
                binding.Path = new PropertyPath("FontSize");
                binding.Source = this.LayoutRoot;


                btnUnit.button.SetBinding(HighlightButton.FontSizeProperty, binding);
                //btnUnit.SetBinding(HighlightButton.FontSizeProperty, binding);

                btnUnit.button.Click += new RoutedEventHandler(UnitButtonControl_Click);

                btnlUnits.Add(btnUnit);

                stpPanel.Children.Add(btnUnit);

                ++count;
            }

            double d = LayoutRoot.FontSize;
        }