使用按钮最小化/最大化用户控件(网格) [英] minimize/maximize a user control (grid) with a button

查看:92
本文介绍了使用按钮最小化/最大化用户控件(网格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个带有各种按钮和文本框的用户控件(该按钮可能调用另一个用户控件),并且我试图弄清楚如何能够最小化和最大化每个用户控件/网格,以便在用户完成输入该控件所需的内容后,该窗口将不会扩展到难以阅读屏幕上的内容的程度.我可以得到一个最小化按钮,单击该按钮可以缩小大小,但是如果他们想返回并更改输入的内容,我不知道如何来回移动.

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!

推荐答案

您的问题对我而言定义不清,但您始终可以使用触发器和ScaleTransform:
在XAML中为MVVM使用EventTrigger –没有代码 [ ^ ]

比例转换:
http://msdn.microsoft.com/en-us/library/system. windows.media.scaletransform.aspx [ ^ ]

但是,我还是不太确定您想要什么,所以如果这个问题不能回答,请改进它:)
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 :)


您可能想使用的是ToggleButton而不是按钮.然后,当按钮被选中时,触发器可以最小化,而您要做的就是取消选中该按钮以再次最大化.
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.


我最终做了
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;
   }
}


这篇关于使用按钮最小化/最大化用户控件(网格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆