0

WPF でイメージ コントロールを移動したい (実際には、イメージは左から右に移動し、左から右に移動し、これを繰り返し繰り返します)、XAML を使用してそれを制御したいと考えています。また、イベントを打ったときにイメージコントロールが動くようにしたいですMouseEnter。以下は私の画像ですGrid

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="TimeZoneDaemonApp.Window1"
Title="TimeZone Browser (CodeBy:CS48516)"  Icon="/TimeZoneDaemonApp;component/Images/Settings.png" Background="{x:Null}" WindowStartupLocation="Manual" Width="704" Height="170" Opacity="1" WindowStyle="None" AllowsTransparency="True">

<Grid PreviewMouseLeftButtonDown="Grid_PreviewMouseLeftButtonDown" PreviewMouseRightButtonDown="Grid_PreviewMouseRightButtonDown" >
    <Grid.Resources>
        <Style TargetType="{x:Type Border}">
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="Black"/>
        </Style>
    </Grid.Resources>
    <Border  OpacityMask="White" Height="100" >
        <Border.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset=".6"/>
                <GradientStop Color="Green" Offset=".9"/>
            </LinearGradientBrush>
        </Border.Background>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="30"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Border Grid.Column="0"><TextBlock FontFamily="@微软雅黑" Padding="0,5,0,0" FontSize="12pt" Foreground="Black" FontWeight="bold" Background="#FFF87800"  TextAlignment="Center"><Run Text="Hong Kong"/></TextBlock></Border>
            <Border Grid.Column="1"><TextBlock Background="#FFB0D428" Padding="0,5,0,0" FontFamily="@微软雅黑" FontSize="16" FontWeight="Bold" Foreground="Black"    Text="New York" TextAlignment="Center"/></Border>
            <Border Grid.Column="2"><TextBlock Background="#FF2283E4" Padding="0,5,0,0" FontFamily="@微软雅黑" FontSize="16" FontWeight="Bold" Foreground="Black"    Text="London" TextAlignment="Center"/></Border>
            <Border Grid.Column="3"><TextBlock Background="#FF20D4D0" Padding="0,5,0,0" FontFamily="@微软雅黑" FontSize="16" FontWeight="Bold" Foreground="Black"    Text="Pairs" TextAlignment="Center"/></Border>
            <Border Grid.Column="4"><TextBlock Background="#FF28D428" Padding="0,5,0,0" FontFamily="@微软雅黑" FontSize="16" FontWeight="Bold" Foreground="Black"    Text="Sydney" TextAlignment="Center"/></Border>
            <Border Grid.Column="5"><TextBlock Background="#FFD040F8" Padding="0,5,0,0" FontFamily="@微软雅黑" FontSize="16" FontWeight="Bold" Foreground="Black"    Text="Brasilia" TextAlignment="Center"/></Border>
            <Border Grid.Column="0" Grid.Row="1"><TextBlock x:Name="HK" Padding="0,5,0,0" Background="#FFA04C00" FontFamily="@微软雅黑" FontSize="12" Foreground="White"   TextAlignment="Center" TextWrapping="NoWrap" TextTrimming="None"><Run Text="Hong Kong"/></TextBlock></Border>
            <Border Grid.Column="1" Grid.Row="1"><TextBlock x:Name="NY" Padding="0,5,0,0" Background="#FF708418" FontFamily="@微软雅黑" FontSize="12" Foreground="White"   TextAlignment="Center" TextWrapping="NoWrap" TextTrimming="None"><Run Text="Hong Kong"/></TextBlock></Border>
            <Border Grid.Column="2" Grid.Row="1"><TextBlock x:Name="UK" Padding="0,5,0,0" Background="#FF184880" FontFamily="@微软雅黑" FontSize="12" Foreground="White"   TextAlignment="Center" TextWrapping="NoWrap" TextTrimming="None"><Run Text="Hong Kong"/></TextBlock></Border>
            <Border Grid.Column="3" Grid.Row="1"><TextBlock x:Name="PS" Padding="0,5,0,0" Background="#FF188480" FontFamily="@微软雅黑" FontSize="12" Foreground="White"   TextAlignment="Center" TextWrapping="NoWrap" TextTrimming="None"><Run Text="Hong Kong"/></TextBlock></Border>
            <Border Grid.Column="4" Grid.Row="1"><TextBlock x:Name="SD" Padding="0,5,0,0" Background="#FF188418" FontFamily="@微软雅黑" FontSize="12" Foreground="White"   TextAlignment="Center" TextWrapping="NoWrap" TextTrimming="None"><Run Text="Hong Kong"/></TextBlock></Border>
            <Border Grid.Column="5" Grid.Row="1"><TextBlock x:Name="BR" Padding="0,5,0,0" Background="#FF7800A8" FontFamily="@微软雅黑" FontSize="12" Foreground="White"   TextAlignment="Center" TextWrapping="NoWrap" TextTrimming="None"><Run Text="Hong Kong"/></TextBlock></Border>

            <Border Grid.Column="0" Grid.Row="2"><TextBlock x:Name="HKT" Padding="0,5,0,0" FontFamily="@Gill Sans MT" FontSize="21pt" Foreground="White"   TextAlignment="Center" FontWeight="Bold"><Run Text="Load"/></TextBlock></Border>
            <Border Grid.Column="1" Grid.Row="2"><TextBlock x:Name="NYT" Padding="0,5,0,0" FontFamily="@Gill Sans MT" FontSize="21pt" Foreground="White"   TextAlignment="Center" FontWeight="Bold"><Run Text="Load"/></TextBlock></Border>
            <Border Grid.Column="2" Grid.Row="2"><TextBlock x:Name="UKT" Padding="0,5,0,0" FontFamily="@Gill Sans MT" FontSize="21pt" Foreground="White"   TextAlignment="Center" FontWeight="Bold"><Run Text="Load"/></TextBlock></Border>
            <Border Grid.Column="3" Grid.Row="2"><TextBlock x:Name="PST" Padding="0,5,0,0" FontFamily="@Gill Sans MT" FontSize="21pt" Foreground="White"   TextAlignment="Center" FontWeight="Bold"><Run Text="Load"/></TextBlock></Border>
            <Border Grid.Column="4" Grid.Row="2"><TextBlock x:Name="SDT" Padding="0,5,0,0" FontFamily="@Gill Sans MT" FontSize="21pt" Foreground="White"   TextAlignment="Center" FontWeight="Bold"><Run Text="Load"/></TextBlock></Border>
            <Border Grid.Column="5" Grid.Row="2"><TextBlock x:Name="BRT" Padding="0,5,0,0" FontFamily="@Gill Sans MT" FontSize="21pt" Foreground="White"   TextAlignment="Center" TextDecorations="None" FontWeight="Bold" Background="Transparent"><Run Text="Load"/></TextBlock></Border>
        </Grid>
    </Border>
    <Image HorizontalAlignment="Left" Height="50" Margin="0,0,0,0"  Source="Images/cloud.png" Stretch="Fill" VerticalAlignment="Top" Width="190">
    </Image>
</Grid>

私は WPF の新しい学習者ですが、誰でもこれを手伝ってもらえますか? どうも。実際、私は SOF: WPFの章を見つけました。プログラムでイメージを (X,Y) に移動する最も簡単な方法は?

まあ、それは私が望むものではありません。

4

1 に答える 1

1

以下にリストされている私の答え:画像を含めるにはCanvasが必要であり、Canvasの「Left」プロパティを使用して画像を移動できます。

<Canvas x:Name="MyCanvas">
        <Canvas.Triggers>
            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard >
                    <Storyboard Storyboard.TargetName="img1" Storyboard.TargetProperty="(Canvas.Left)">
                        <DoubleAnimation From="0" To="514" Duration="0:0:20" AccelerationRatio=".2" DecelerationRatio=".8" RepeatBehavior="23:59:59" AutoReverse="True"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Canvas.Triggers>
于 2012-08-10T01:25:00.933 に答える