好吧,这是一个棘手的情况。我的 WPF 项目中有 2 个 xaml 文件,VoltageChannelView.xaml 和 VoltageView.Xaml,在我的 VoltageView.xaml 中,我将网格分为 3 行,如下所示:
电压视图:
<Grid Style="{DynamicResource styleBackground}" >
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" >
</Grid>
<Grid Name="ContentGrid" Grid.Row="1" Height="Auto" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Name="Label11" />
<RowDefinition Name="Label22" />
<RowDefinition Name="Label33" />
<RowDefinition Name="Label44" />
<RowDefinition Name="Label55" />
<RowDefinition Name="Label66" />
<RowDefinition Name="Label77" />
<RowDefinition Name="Label88" />
<RowDefinition Name="Label99" />
</Grid.RowDefinitions>
</Grid>
<Grid Grid.Row="2" >
<Button Content="Bavaria 2" FontSize="13" Height="25" HorizontalAlignment="Left" Margin="30,0,0,0" Name="RefreshBtn" VerticalAlignment="Center" Width="105" />
<Button Content="Redhook" FontSize="13" Height="25" HorizontalAlignment="Center" Margin="0,0,0,0" Name="Refresh1Btn" VerticalAlignment="Center" Width="105" />
<Button Content="Bavaria 1" FontSize="13" Height="25" HorizontalAlignment="Right" Margin="0,0,30,0" Name="Refresh2Btn" VerticalAlignment="Center" Width="105" />
</Grid>
</Grid>
现在您可以注意到Grid.Row="1"我将网格划分为 9 行。
电压通道视图:
<CheckBox Content="On" Grid.Column="3" Height="Auto" HorizontalAlignment="Center" Margin="0" Name="On" VerticalAlignment="Center" />
<Button Content="Set" Grid.Column="1" Height="23" HorizontalAlignment="Center" Margin="85,0,0,0" Name="Set" VerticalAlignment="Center" Width="75" />
<TextBox Grid.Column="1" Height="23" HorizontalAlignment="Center" Margin="0,0,80,0" Name="textBox1" VerticalAlignment="Center" Width="70" />
<Label Content="VDD__Main" Grid.Column="0" Height="15" HorizontalAlignment="Center" Margin="0,0,70,0" Name="VoltageLabel" VerticalAlignment="Center" />
<Label Content="0.0 V" Grid.Column="2" Height="15" HorizontalAlignment="Center" Margin="0" Name="CurrentLabel" VerticalAlignment="Center" />
现在我的 Grid.Row="2" 中有 3 个按钮,我的要求是,当我单击“Bavaria 2”按钮时,我希望将 VoltageChannelView 的内容放在我的VoltageView Grid.Row="1" 中。这是诀窍,它应该动态生成整个内容 5 次。即在 Grid.Row="1" 的 9 行中,VoltageChannelView 的内容应该出现在前 5 行中,每行一个。
在单击“Bavaria1”时,它应该生成内容 8 次,依此类推。基本上WPF中是否可以根据每个按钮单击生成VoltageChannelView“n”次的内容并将其显示在我的VoltageView中??????