I'm trying to set an Image
HorizontalAlignment property in code, not XAML, but it fails to work:
Grid grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); Image img = new Image() { Source = new Uri("myImage.png") }; Grid.SetColumn(img, 1); img.HorizontalAlignment = HorizontalAlignment.Right; grid.Children.Add(img);
This code should create a grid with a single row and two columns, then the image should be added to the second column and be anchored all the way to the right, but the image stays anchored on the left side of the second column.
How can this be? VerticalAlignment works correctly on the image...