查找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; }