Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have several user controls that have various buttons and text boxes (the button might call another user control), and I am trying to figure out how to be able to minimize and maximize each of the user controls/grids so that when the user is finished entering what is needed for that control the window won't expand to the point where it is hard to read what is on the screen. I can get a minimize button that when clicked it shrinks the size, but I don't know how to go back and forth if they wanted to go back and change something they entered.
HTML
<Button Name="minimize" Grid.Row="0" Grid.Column="5" Width="20" Height="20" HorizontalAlignment="Center" Click="minimize_Click">
        <TextBlock Text="-" FontSize="12" FontWeight="Bold" />
</Button>  

with the code behind
C#
private void minimize_Click(object sender, RoutedEventArgs e)
{
    this.Height = 50;
}


I am sure there is a better way - maybe some way to do both the minimize/maximize with the same button?? Any suggestions will be appreciated!
Posted

You problem is not well defined to me, but you could always use triggers and ScaleTransform:
Using EventTrigger in XAML for MVVM – No Code Behind[^]

Scale transform:
http://msdn.microsoft.com/en-us/library/system.windows.media.scaletransform.aspx[^]

But again, Im not quite sure what you want, so if this dosnt answer the question pleas Improve it :)
 
Share this answer
 
What you might want to do is use a ToggleButton instead of a button. Then a trigger can minimize when the button IsChecked, and all you have to do is uncheck it to maximize again.
 
Share this answer
 
I ended up doing
HTML
<button grid.row="0" grid.column="5" width="20" height="20" click="minimize_Click" horizontalalignment="Right" mode="hold" />    <Grid>
      <TextBlock Name="minSize" Text="-" FontSize="12" FontWeight="Bold" Visibility="Visible"/>
      <TextBlock Name="maxSize" Text="+" FontSize="12" FontWeight="Bold" Visibility="Hidden" />
    </Grid>
</Button>


then in the code behind
C#
double height = 0;
private void minimize_Click(object sender, RoutedEventArgs e)
{
   if (minSize.Visibility == System.Windows.Visibility.Visible)
   {
      height = this.Height;
      this.Height = 50;
      minSize.Visibility = System.Windows.Visibility.Collapsed;
      maxSize.Visibility = System.Windows.Visibility.Visible;
   }
   else
   {
      minSize.Visibility = System.Windows.Visibility.Visible;
      maxSize.Visibility = System.Windows.Visibility.Collapsed;
      this.Height = height;
   }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900