在wpf中缩小窗口

时间:2012-10-03 05:16:46

标签: .net wpf xaml

如何简单地缩小窗口wpf。我不想要任何滑块控件,我想要的是在执行程序时缓慢缩小的窗口。我很欣赏XAML中的一段代码。

我正在使用VS 2010和.NET 3.5。

谢谢。

1 个答案:

答案 0 :(得分:1)

<Window
   x:Name="window"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   AllowsTransparency="True"
   SizeToContent="WidthAndHeight"
   WindowStyle="None">
   <Canvas x:Name="grid">
      <Canvas.RenderTransform>
         <ScaleTransform x:Name="zoom" ScaleX="1" ScaleY="1" />
      </Canvas.RenderTransform>
      <Canvas.Triggers>
         <EventTrigger RoutedEvent="Loaded">
            <EventTrigger.Actions>
               <BeginStoryboard>
                  <Storyboard>
                     <DoubleAnimation
                        Duration="00:00:03"
                        From="400"
                        Storyboard.TargetName="grid"
                        Storyboard.TargetProperty="Height"
                        To="200"/>
                     <DoubleAnimation
                        Duration="00:00:03"
                        From="400"
                        Storyboard.TargetName="grid"
                        Storyboard.TargetProperty="Width"
                        To="200"/>
                     <DoubleAnimation
                        Duration="00:00:03"
                        From="1"
                        Storyboard.TargetName="zoom"
                        Storyboard.TargetProperty="ScaleX"
                        To="0.5"/>
                     <DoubleAnimation
                        Duration="00:00:03"
                        From="1"
                        Storyboard.TargetName="zoom"
                        Storyboard.TargetProperty="ScaleY"
                        To="0.5"/>
                  </Storyboard>
               </BeginStoryboard>
            </EventTrigger.Actions>
         </EventTrigger>
      </Canvas.Triggers>
      <StackPanel Width="200" Height="200">
         <Button>Hello world!</Button>
         <ListBox>
            <ListBoxItem>One</ListBoxItem>
            <ListBoxItem>Two</ListBoxItem>
            <ListBoxItem>Three</ListBoxItem>
         </ListBox>
      </StackPanel>
   </Canvas>
</Window>