I am trying to find a way to access the window height of my screen from my view model, so that I can set my MaxHeight to be a percentage of the window height.
XAML
<UserControl>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SizeChanged">
<i:InvokeCommandAction Command="{Binding SizeChangedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<Grid.RowDefinitions/>
<ListBox Grid.Row="0"
Content={Binding SomeContent}
MaxHeightMaxHeight="{Binding PercentageMaxHeight}"/>
<Button Content="ClickMe"
Grid.Row="1" />
</Grid>
<UserControl/>
To be clear, this is not my actual complete XAML. The idea is that I want my ListBox to have a maximum height that is a percentage of the screen size so that my button is always right below my listbox, but the listbox does not push the button off the screen when it's too filled up.
View Model
public PercentageMaxHeight;
public ICommand SizeChangedCommand => new RelayCommand(SizeChangedCommandExecuted);
private void SizeChangedCommandExecuted()
{
/*I am looking for a way to access ActualHeight, or any other way of getting the height of my window
here, so I can update PercentageMaxHeight. */
}
I don't want to set it from the code behind my XAML, because I am trying to follow MVVM.