zoukankan      html  css  js  c++  java
  • WPF 设置Button的content为多行模式

    查找button的子元素是个TextBlock,再设置它的TextWrappingProperty属性为 TextWrapping.Wrap。

      Button btn2 = new Button() {Content="fdhfhfhfhfghfhfhfhfhhfh",Width=88};
                btn2.Loaded += Btn2_Loaded;
                gridRoot.Children.Add(btn2);
    
    
            }
    
            private void Btn2_Loaded(object sender, RoutedEventArgs e)
            {
                Button btn = (sender as Button);
                var o = GetChildObjects<TextBlock>(btn, typeof(TextBlock));
                o[0].SetValue(TextBlock.TextWrappingProperty, TextWrapping.Wrap);
    
            }
    
          
    
            /// <summary>
            /// 根据类型查找子元素
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="obj"></param>
            /// <param name="typename"></param>
            /// <returns></returns>
            public List<T> GetChildObjects<T>(DependencyObject obj, Type typename) where T : FrameworkElement
            {
                DependencyObject child = null;
                List<T> childList = new List<T>();
    
                for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
                {
                    child = VisualTreeHelper.GetChild(obj, i);
    
                    if (child is T && (((T)child).GetType() == typename))
                    {
                        childList.Add((T)child);
                    }
                    childList.AddRange(GetChildObjects<T>(child, typename));
                }
                return childList;
            }
    

      

    fffffffffffffffff
    test red font.
  • 相关阅读:
    一位区域销售经理百条经验手记
    PAIP.FLEX与JAVA数据对应关系.txt
    转:java生成EXCEL表格(POI vs JXL)
    逆向分析工具介绍
    applet与SERLET交互...
    AT命令集(
    关于WINDOWS超级终端的使用来调试MODEM,串口.
    poj1331
    poj1338
    poj1325
  • 原文地址:https://www.cnblogs.com/wgscd/p/15069704.html
Copyright © 2011-2022 走看看