You could put the Button
in a star-sized Grid
that fills the window:
<Window ...>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Button Content="..." Grid.Column="1" />
</Grid>
</Window>
Or handle the SizeChanged
event of the window and set the button's Width
property to this.Width / 3.0
:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SizeChanged += OnSizeChanged;
}
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
btnWebsite.Width = Width / 3.0;
}
}