Consider a Window W, Button B, and TextBlock T where W.Content = B and B.Content = T T may be aligned inside B by setting B.HorizontalContentAlignment and B.VerticalContentAlignment. However T.HorizontalAlignment and T.VerticalAlignment have no effect. B may be aligned inside W by setting B.HorizontalAlignment and B.VerticalAlignment. W.HorizontalContentAlignment and W.VerticalContentAlignment have no effect. Is there a rule that may be deployed to determine whether these properties should be set on the parent (using HorizontalContentAlignment and VerticalContentAlignment) or on the child (using HorizontalAlignment and VerticalAlignment)? It seems a bit unfair to have to guess. The documentation is not very helpful in this regard. {example code follows } using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; namespace AlignmentQuestions { class MainWindow : Window { [STAThread] public static void Main() { new Application().Run(new MainWindow()); } public MainWindow() { Width = 2 * 96; Height = 2 * 96; Button button = new Button(); TextBlock text_block = new TextBlock(new Run("Button")); button.Content = text_block; this.Content = button; //align text in button //works button.VerticalContentAlignment = VerticalAlignment.Top; //does not work //text_block.VerticalAlignment = VerticalAlignment.Top; //align button in window //does not work //HorizontalContentAlignment = HorizontalAlignment.Left; //works button.HorizontalAlignment = HorizontalAlignment.Left; } } } -- Martin
As I want to know answer on this question I redirect your post to http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&SiteID=1 "abc" ???????/???????? ? ???????? ?????????: news:%23JWyb9a$HHA.4836@TK2MSFTNGP06.phx.gbl... > > Consider a Window W, Button B, and TextBlock T where > > W.Content = B > and > B.Content = T > > > T may be aligned inside B by setting B.HorizontalContentAlignment and > B.VerticalContentAlignment. However T.HorizontalAlignment and > T.VerticalAlignment have no effect. > > B may be aligned inside W by setting B.HorizontalAlignment and > B.VerticalAlignment. W.HorizontalContentAlignment and > W.VerticalContentAlignment have no effect. > > > Is there a rule that may be deployed to determine whether these > properties should be set on the parent (using > HorizontalContentAlignment and VerticalContentAlignment) or on the > child (using HorizontalAlignment and VerticalAlignment)? It seems a bit > unfair to have to guess. The documentation is not very helpful in this > regard. > > > {example code follows } > > using System; > using System.Windows; > using System.Windows.Controls; > using System.Windows.Documents; > > namespace AlignmentQuestions { > class MainWindow : Window { > > [STAThread] > public static void Main() { > new Application().Run(new MainWindow()); > } > > public MainWindow() { > Width = 2 * 96; Height = 2 * 96; > Button button = new Button(); > TextBlock text_block = new TextBlock(new Run("Button")); > button.Content = text_block; > this.Content = button; > > //align text in button > //works > button.VerticalContentAlignment = VerticalAlignment.Top; > > //does not work > //text_block.VerticalAlignment = VerticalAlignment.Top; > > > //align button in window > //does not work > //HorizontalContentAlignment = HorizontalAlignment.Left; > > //works > button.HorizontalAlignment = HorizontalAlignment.Left; > } > } > } > > > > > -- > > Martin