嗨我有一組員工數據,其中包括照片,說明,職位名稱,薪水。我必須將每個員工的數據顯示在獨立的面板控制結構中,這意味着如果我有10名員工,則會有10個面板。我必須在有兩列的網格中顯示這些面板。每列中的面板寬度也會根據主頁面大小而變化。如何將用戶控件的數組放入Grid的列
0
A
回答
0
爲什麼不用一個單獨的userControl表示僱員數據,然後使用Wrap面板來顯示僱員。這種方法將處理可變數量的員工。
爲了更好地說明這裏我的想法是一些代碼:
的具有的MainPage與填充可用空間WrapPanel的網格。
MainPage.xaml中
<UserControl
x:Class="SilverlightApplication2.MainPage"
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"
xmlns:ct="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="WhiteSmoke">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="200"/>
<RowDefinition/>
<RowDefinition Height="200"/>
</Grid.RowDefinitions>
<ct:WrapPanel x:Name="panel1" Grid.Row="1" Grid.Column="1"
Background="Aqua" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"/>
</Grid>
</UserControl>
MainPage.xaml.cs中
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.DataContext = this;
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded (object sender, RoutedEventArgs e)
{
for (int x = 0; x <= 10; x++)
{
panel1.Children.Add(new ChildControl());
}
}
}
我加入ChildWindow控件定義見下文以顯示WrapPanel如何適應其子女的可用空間的呈現。
ChildWindow.xaml
<UserControl
x:Class="SilverlightApplication2.ChildControl"
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"
Width="100"
Height="100">
<Grid x:Name="LayoutRoot" Background="PowderBlue">
<TextBlock Text="ChildControl"/>
</Grid>
</UserControl>
如果我錯過了你的觀點,請給一些更多的澄清。
相關問題
- 1. 如何將url文件放入javascript中的數組列表中
- 2. 如何將控件放到用戶控件的面板上?
- 3. 如何將命令和字段放入一列kendoui grid
- 4. 如何將文件中的數據放入javascript數組中
- 5. 如何使用eval將用戶輸入放入列表中?
- 6. 如何將一組單詞放入使用python的數組中
- 7. 如何將用戶輸入的整數插入到數組中?
- 8. 如何將自定義用戶控件放入WPF中的HierarchicalDataTemplate中?
- 9. Ada如何從用戶獲得輸入的整數列表並將其放入數組
- 10. 如何將外部文件中的值放入數組中?
- 11. Powershell - 如何將我的.dat文件放入數組中?
- 12. 如何將數組放入Ruby中的數組
- 13. 如何將變量放入數組
- 14. 如何將Regex.Matches放入數組中?
- 15. 如何將對象放入數組
- 16. 如何將數組放入addStaff(const Staff&)
- 17. 如何將數字放入某些組?
- 18. 如何將數組放入div
- 19. 如何將UIImage放入AnyObject數組?
- 20. 如何將數組放入會話?
- 21. 如何將數組放入方法?
- 22. 如何將實體放入數組Swift
- 23. 如何將聲音放入數組中?
- 24. 如何將循環放入數組php
- 25. 如何讓用戶控制數組中的輸入?
- 26. 如何將數字的數字放入整數數組中?
- 27. 如何將URL參數放入ZF2控制器的「params」控制器插件?
- 28. 如何使用python將此json響應的「數據」組件放入數據框?
- 29. 如何將數據輸入到用戶定義類的數組列表中?
- 30. 如何把JSON放入EXTJS Grid?
爲什麼兩列?如果有更多的員工能夠適應窗口,會發生什麼? – AnthonyWJones 2010-02-17 08:36:40