【发布时间】:2018-03-25 23:42:00
【问题描述】:
我在 xaml 上的代码看起来像这样
</Grid>
<Grid Grid.Column="1" Grid.Row="0" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="*" ></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Center" Content="Updates Avalable"></Label>
<Button Name="btnUpdate" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center" MouseDoubleClick="btnUpdate_MouseDoubleClick" >Check For Available Updates</Button>
<StackPanel Name="controlHolder" Grid.Column="0" Grid.Row="1">
</StackPanel>
</Grid>
然后我创建一个自定义控件并尝试像这样将它添加到 stackPanel
File_Type_Control_Green ftcg = ftc.GeneratefileTypeControl("file", "hello", "3mb", "someurl", "2-3-4");
controlHolder.Children.Add(ftcg);
但是,当我这样做时,它实际上是把它放在按钮内。
在 windows 窗体中,您可以将控件添加到面板没有问题,但这似乎是 wpf 中的一个大问题。我不知道如何解决这个问题。有人可以指出我正确的方向吗?
主要目标是将新控件动态添加到堆栈面板。我还没有这样做,但我会添加 xy 位置以正确分隔控件,假设您可以像在面板中那样做。
谢谢!
【问题讨论】:
-
您让 Button 和 StackPanel 填充了相同的网格列和行,因此您无法从视觉上区分它们,即使 UserControl 是 StackPanel 的子项。将它们放在不同的网格单元格中或在堆栈面板上设置背景颜色,以便您可以看到 UserControl 的位置。
-
.......................所以这是那些日子之一,是吗?
标签: c# xaml custom-controls stackpanel