WPF通过Combobox选择在主窗口上加载不同的动画

时间:2012-12-07 15:48:58

标签: vb.net visual-studio-2010

我正在尝试在Visual Basic 2010 WPF Mainwindow中上传不同的Path动画,选择组合框中列出的动画的名称。 所以在WPF中,我的主窗口包含一个组合框,此时有2个名字,我还有Window1和Window2,每个窗口都有不同的PathAnimation。 我不知道程序运行时如何在主窗口中加载动画1或动画2。 我有点失落

1 个答案:

答案 0 :(得分:0)

这是一个简单的例子,我把它放在一起,它使用ViewBox作为容器。看看这是否适合你

<强> MainWindow.xmal

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="697" Width="697" xmlns:my="clr-namespace:WpfApplication1">
    <Grid>
        <Viewbox Name="TrackContainer"  VerticalAlignment="Top"  HorizontalAlignment="Stretch"></Viewbox>
        <Button Content="Button" Height="23" HorizontalAlignment="Center"  Margin="360,600,240,0" Name="Button1" VerticalAlignment="Top" Width="75" />
        <ComboBox Height="23" Name="ComboBox1" Width="120" SelectionChanged="ComboBox1_SelectionChanged" Margin="41,600,514,35">
            <ComboBoxItem Content="Daytona" />
            <ComboBoxItem Content="SecondTrack" />
            <ComboBoxItem Content="None" />
        </ComboBox>
    </Grid>
</Window>

<强> MainWindow.xaml.vb

Class MainWindow 
    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click

        Select Case CType(ComboBox1.SelectedValue, ComboBoxItem).Content.ToString
            Case "Daytona"
                CType(TrackContainer.Child, UserControl1).runPathAnimation()
            Case "SecondTrack"
                CType(TrackContainer.Child, UserControl2).runPathAnimation()

        End Select

    End Sub

    Private Sub ComboBox1_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
        Dim cmbox As ComboBox = CType(sender, ComboBox)
        Select Case CType(cmbox.SelectedValue, ComboBoxItem).Content.ToString
            Case "Daytona"
                TrackContainer.Child = New UserControl1()
            Case "SecondTrack"
                TrackContainer.Child = New UserControl2()
            Case "None"
                TrackContainer.Child = Nothing
        End Select
    End Sub
End Class