0
A
回答
4
TreeView可以用於這種方法。該項目容器的樣式應該是定製,如下面的鏈接,
http://www.codeproject.com/Articles/17025/Custom-TreeView-Layout-in-WPF
2
你也可以做到這一點使用ListBox控件。
的Xaml
<Window x:Class="DecoraSnap.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowState="Maximized" >
<Window.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border>
<ContentPresenter></ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel Margin="100,0,0,0" Orientation="Horizontal">
<Border Height="50" Width="100" VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1">
<TextBlock FontWeight="Bold" Text="Meassage" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0"/>
</Border>
<Separator Height="1" Background="Black" VerticalAlignment="Center" Width="50"></Separator>
<Border x:Name="BorderWidth" Width="1" Background="Black" ></Border>
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemsSource="{Binding RequestList}" BorderBrush="Transparent" BorderThickness="0" x:Name="lst">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid x:Name="UniformGrid1" Height="{Binding ElementName=lst,Path=ActualHeight}" Loaded="UniformGrid1_Loaded_1" Columns="1" ></UniformGrid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<Separator Width="50" Height="1" Background="Black"></Separator>
<Border Height="50" Width="100" BorderBrush="Black" BorderThickness="1">
<TextBlock FontWeight="Bold" Text="{Binding Reaquest}" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0"/>
</Border>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Border Background="Black" Height="1" Width="50"></Border>
<!--You can implement border width like "UniformGrid1_Loaded_1" event -->
<Border Width="1" Background="Black" Height="235" ></Border>
<ListBox Background="Transparent" HorizontalAlignment="Center" BorderBrush="Transparent" ItemsSource="{Binding Models}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid x:Name="Uniformgrid2" Columns="1"></UniformGrid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Separator Width="50" Height="1" Background="Black"></Separator>
<Grid Height="40" Width="100" >
<Border BorderBrush="Black" BorderThickness="1">
<TextBlock FontWeight="Bold" Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0"/>
</Border>
</Grid>
<Separator Width="50" Height="1" Background="Black"></Separator>
<Grid Height="100" Width="100" >
<Rectangle Stroke="Black" Fill="LightYellow" StrokeThickness="1" StrokeDashArray="1,2"></Rectangle>
<TextBlock FontWeight="Bold" Foreground="Silver" Text="{Binding SameName}" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0"/>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
C#代碼
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<Meassage> RequestList = new List<Meassage>();
RequestList.Add(new Meassage()
{
Reaquest = "request",
Models = new List<Commands>(){new Commands(){ Name = "command", SameName="command"},
new Commands(){Name = "Metainfo", SameName="MetaInfo"},
new Commands(){Name = "data", SameName="result" },}
});
RequestList.Add(new Meassage()
{
Reaquest = "response",
Models = new List<Commands>(){new Commands(){ Name = "command", SameName="command"},
new Commands(){Name = "Metainfo", SameName="MetaInfo"},
new Commands(){Name = "data", SameName="result" },}
});
lst.ItemsSource = RequestList;
}
private void UniformGrid1_Loaded_1(object sender, RoutedEventArgs e)
{
UniformGrid un = sender as UniformGrid;
var ab= un.ActualHeight;
var ItemsCount = un.Children.Count;
var SingleHeight = ab/ItemsCount;
BorderWidth.Height = SingleHeight * (ItemsCount - 1);
}
}
public class Meassage
{
public string Reaquest { get; set; }
public List<Commands> Models { get; set; }
}
public class Commands
{
public string Name { get; set; }
public string SameName{ get; set; }
}
結果
1
正如XAML情人所提到的,TreeView控件在這裏將是更好的選擇。您可以將它與HierarchicalDataTemplate一起使用,您可以在其中設置ItemsSource並綁定到視圖模型。
http://msdn.microsoft.com/en-us/library/dd759035(v=vs.95).aspx
在鏈路的例子使用一個簡單的TextBlock顯示項目名稱。如果您必須添加其他項目(如樹視圖項目的上下文菜單),則可以在HieraichalDataTemplate中添加這些項目。然後,爲了更新外觀,您必須自定義TreeViewItem樣式或ItemsContainerStyle。您可以在此處添加圖標,並且如果您需要在加載時保持樹打開,還可以自定義IsExpanded屬性。樹視圖還允許您瀏覽控件並從節點中查找子項。
相關問題
- 1. WPF複雜的分級數據模板
- 2. 基地分級同步控制器爲異步控制器隱藏複雜
- 3. 控制複雜流程nodejs
- 4. 複雜線程控制
- 5. 複雜(?)訪問控制
- 6. 複雜的SQL查詢或控制器中的複雜處理?
- 7. Rails的控制檯複雜的查詢
- 8. 複雜頁面的Laravel控制器
- 9. 複雜佈局的內容控制
- 10. 測試複雜的控制器組件
- 11. WPF - 複雜TextBlock的佈局
- 12. WPF中的複雜視圖
- 13. JavaScript中的複雜級聯
- 14. WPF檢測滾動父級控制
- 15. 控制流程圖和圈複雜度
- 16. WPF的控制檯控制
- 17. 複雜分組
- 18. 分析複雜
- 19. WPF綁定複雜對象
- 20. 確定複雜性等級
- 21. WPF用戶控件:使編輯的複雜性
- 22. WPF:如何創建複雜的用戶控件? (如GDI +)
- 23. 控制CockroachDB中的行級分佈?
- 24. 以編程方式WPF複製控件
- 25. 以編程方式複製WPF控件
- 26. WPF色帶控制控制
- 27. WPF:複雜圖像的快速繪製/縮放
- 28. 複雜WPF的組合框Caliburn.Micro
- 29. WPF - 組合框的複雜綁定
- 30. 具有多個分組級別的複雜條線圖