1

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

我正在使用带有 .NET 3.5 的 VS 2010。

谢谢你。

4

1 回答 1

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>
于 2012-10-03T07:28:41.423 回答