Click here to Skip to main content
11,641,209 members (63,114 online)
Rate this: bad
good
Please Sign up or sign in to 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.
<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
 
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 28-Aug-12 7:12am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I ended up doing
<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
 
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;
   }
}
  Permalink  

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

  Print Answers RSS
0 Mika Wendelius 400
1 OriginalGriff 205
2 DamithSL 203
3 CPallini 185
4 Afzaal Ahmad Zeeshan 129
0 Mika Wendelius 400
1 OriginalGriff 205
2 DamithSL 203
3 CPallini 185
4 Afzaal Ahmad Zeeshan 129


Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100