-
Notifications
You must be signed in to change notification settings - Fork 2
/
DataGridInDataGrid.xaml
221 lines (221 loc) · 11.2 KB
/
DataGridInDataGrid.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<Window
x:Class="WpfApp1.DataGridInDataGrid"
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:local="clr-namespace:WpfApp1"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="DataGridInDataGrid"
Width="800"
Height="600"
MinWidth="800"
Loaded="Window_Loaded"
mc:Ignorable="d">
<Window.Resources>
<!-- 第一部分:内嵌的ListBox用什么布局 -->
<ItemsPanelTemplate x:Key="itemspanel">
<StackPanel VerticalAlignment="Center" Orientation="Horizontal" />
</ItemsPanelTemplate>
<!-- 第二部分:内嵌ListBox的项模板 -->
<DataTemplate x:Key="itemstemplate">
<!--
用Canvas来装可以精确定位项,但没有水平滚动条Canvas.Left="{Binding Path=LeftWidth}" Canvas.Top="0"
只好用StackPanel来布局
-->
<StackPanel Orientation="Vertical">
<Border
BorderBrush="Blue"
BorderThickness="1"
CornerRadius="3">
<StackPanel Margin="5,0,5,0" Orientation="Horizontal">
<!-- 这里是装项内容 -->
<TextBlock
Margin="2"
VerticalAlignment="Center"
Text="{Binding Path=ChoseName}" />
<TextBox
Margin="2"
VerticalAlignment="Center"
IsReadOnly="True"
Text="{Binding Path=ChoseContent}" />
</StackPanel>
</Border>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DataGrid
Name="datagrid1"
Grid.Row="0"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="ID值" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Expander Collapsed="Expander_Collapsed" Expanded="Expander_Expanded" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn
Width="auto"
Binding="{Binding questionName}"
Header="题目"
IsReadOnly="True" />
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid
Margin="30,10,0,20"
AutoGenerateColumns="False"
Background="Green"
ItemsSource="{Binding choseItems}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ChoseName}" Header="选项名" />
<DataGridTextColumn Binding="{Binding ChoseContent}" Header="选项内容举例" />
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
<ListBox x:Name="listBox" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate>
<WrapPanel>
<Border
Width="740"
MaxWidth="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}, Path=ActualWidth}"
Margin="2"
BorderBrush="Black"
BorderThickness="0.5">
<Grid>
<Grid.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="30,10,0,10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="18"
Text="编号:" />
<TextBlock
Grid.Row="0"
Grid.Column="0"
Width="120"
Margin="20,10,0,10"
HorizontalAlignment="Center"
FontSize="18"
Text="{Binding questionID}" />
<TextBlock
Grid.Row="0"
Grid.Column="1"
Margin="30,10,0,10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="18">
名称:
</TextBlock>
<TextBlock
Grid.Row="0"
Grid.Column="1"
Width="120"
Margin="20,10,0,10"
HorizontalAlignment="Center"
FontSize="18"
Text="{Binding questionName}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Width="100"
Margin="30,10,0,10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="18"
Text="状态:" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Width="120"
Margin="20,10,0,10"
FontSize="18"
Text="{Binding questionName}" />
<TextBlock
Grid.Row="1"
Grid.Column="1"
Width="100"
Margin="30,10,0,10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="18"
Text="时间:" />
<TextBlock
Grid.Row="1"
Grid.Column="1"
Width="120"
Margin="20,10,0,10"
FontSize="18"
Text="{Binding questionName}" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
Width="100"
Margin="30,10,0,10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="18"
Text="内容:" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
Width="120"
Margin="20,10,0,10"
FontSize="18"
Text="{Binding questionName}" />
<ToggleButton
x:Name="toggleButton"
Grid.Row="1"
Grid.Column="2"
Width="100"
Content="Toggle" />
</Grid>
<DataGrid
x:Name="datagrid3"
Grid.Row="1"
AutoGenerateColumns="False"
Background="Green"
ItemsSource="{Binding choseItems}"
PreviewMouseWheel="datagrid3_PreviewMouseWheel"
Visibility="{Binding IsChecked, ElementName=toggleButton, Converter={StaticResource BoolToVisibilityConverter}}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ChoseName}" Header="选项名" />
<DataGridTextColumn Binding="{Binding ChoseContent}" Header="选项内容举例" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Border>
</WrapPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>