我正在尝试在 Visual Basic 2010 WPF 主窗口中上传不同的路径动画,选择组合框中列出的动画名称。因此,在 WPF 中,我的主窗口包含一个组合框,此时包含 2 个名称,并且我还有 Window1 和 Window2,每个都有不同的 PathAnimation。我不知道程序运行时如何在主窗口中加载动画 1 或动画 2。我有点失落
问问题
349 次
1 回答
0
这是我放在一起的一个简单示例,它使用 ViewBox 作为容器。看看这是否适合你
主窗口.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>
主窗口.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
于 2012-12-18T02:44:39.647 回答