Dear sir,
I am new to WPF, I try to developing a simple panel. In the panel arranging the textbox and textblock to Left, Right and Centre.
How can i get the Textbox HorizontalAlignment is Left or Right and Verticalaignment is top or bottom from the XAML code
my code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
namespace MySimplePanel
{
public class MySimplePanelClass : Panel
{
protected override Size MeasureOverride(Size availableSize)
{
Size maxSize = new Size();
foreach (UIElement child in this.Children)
{
child.Measure(availableSize);
maxSize.Height = Math.Max(child.DesiredSize.Height, maxSize.Height);
maxSize.Width = Math.Max(child.DesiredSize.Width, maxSize.Width);
}
return maxSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
foreach (UIElement child in InternalChildren)
{
child.Arrange(new Rect(finalSize));
}
return finalSize;
}
}
XAML code :
<window x:class="MySimplePanel.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MySimplePanel"
Title="MainWindow" Height="350" Width="525">
<grid>
<local:mysimplepanelclass grid.columnspan="5" horizontalalignment="Stretch" xmlns:local="#unknown">
<textbox height="23" horizontalalignment="Left" margin="0,10,0,0" name="textBox1" verticalalignment="Top" width="120" />
<textbox height="23" horizontalalignment="Left" margin="100,10,0,0" name="textBox2" verticalalignment="Top" width="120" textalignment="Center" />
<textbox height="23" horizontalalignment="Right" margin="200,10,0,0" name="textBox3" verticalalignment="Top" width="120" />
<textbox height="23" horizontalalignment="Right" margin="360,10,0,0" name="textBox4" verticalalignment="Top" width="120" />
</local:mysimplepanelclass>
</grid>
</window>
Thanks all