DataTemplateSelector(项目)
今天记录一下前端项目中使用DataTemplateSelector的步骤。
首先看项目目录:
这里有一个FiledType.cs文件,还有一个RefineSearch.xaml以及其后台程序。FiledType.cs里是关于要使用的类的属性的定义,里面有一个类的构造,这里可以看到FiledType的类的构造函数,里面的参数是我们后面要做的ComboBox里面items类型所有的属性。即ComboBox里每一项都是一个复杂的FiledType类型,而且里面包含如下这些属性信息。
FieldType(int sortOrder, string readableName, string internalName, string dataType)
如果选择ComboBox里某一选项的dataType是string类型,那么后面只出现一个textbox,如果是其他类型比如double,那么出现两个textbox,用来输入MaxDoubleInput和MinDoubleInput。
FiledType.cs 文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; namespace PfgDbTestHarness { public class FieldType : INotifyPropertyChanged //FieldType类型数据有任何改变将自动通知CLR更新Textbox后面的数据 { public event PropertyChangedEventHandler PropertyChanged; private string _readableName; public string ReadableName { get { return _readableName; } set { if (_readableName != value) { _readableName = value; OnPropertyChanged("ReadableName"); } } } public string InternalName { get; set; } public string DataType { get; set; } private string _stringInput; //这个是Ryan帮我加的。用来保存在Textbox里键入的数据:string类型或者double类型的MaxDoubleInput和MinDoubleInput public string StringInput { get { return _stringInput; } set { if (_stringInput != value) { _stringInput = value; OnPropertyChanged("StringInput"); } } } private string _minDoubleInput; public string MinDoubleInput { get { return _minDoubleInput; } set { if (_minDoubleInput != value) { _minDoubleInput = value; OnPropertyChanged("MinDoubleInput"); } } } private string _maxDoubleInput; public string MaxDoubleInput { get { return _maxDoubleInput; } set { if (_maxDoubleInput != value) { _maxDoubleInput = value; OnPropertyChanged("MaxDoubleInput"); } } } private readonly int _sortOrder; public int SortOrder { get { return _sortOrder; } } public override string ToString() { return ReadableName; } public FieldType(int sortOrder, string readableName, string internalName, string dataType) //一个FiledType类型的对象有以下4个属性的信息 { _sortOrder = sortOrder; ReadableName = readableName; InternalName = internalName; DataType = dataType; } public virtual void OnPropertyChanged(string property) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(property)); } } } }
下面我们要实现ComboBox里选择的item的dataType是string类型的,后面自动切换成一个TextBox的模板。选择的item为其他类型则切换成两个Textbox的模板(这里只给出了item的dataType是Double的情况,其他类型程序不全。)
定义dataTypeTemplateSelecter类。
RefineSearch.xaml.cs:
1 using System; 2 using System.Collections.Generic; 3 using System.Windows; 4 using System.Windows.Controls; 5 using System.Windows.Media; 6 using System.Windows.Media.Imaging; 7 8 namespace PfgDbTestHarness 9 { 10 /// <summary> 11 /// Interaction logic for AdvancedSearch.xaml 12 /// </summary> 13 public partial class RefineSearch //: Window 14 { 15 private readonly List<FieldType> _fieldTypes = new List<FieldType>(); 16 private readonly List<ComboBox> _searchComboBoxes = new List<ComboBox>(); 17 //private readonly List<TextBox> _minTextBoxes = new List<TextBox>(); 18 //private readonly List<TextBox> _maxTextBoxes = new List<TextBox>(); 19 //private readonly List<CalendarControl> _minCalendarControls = new List<CalendarControls>(); 20 //private readonly List<CalendarControl> _maxCalendarControls = new List<CalendarControls>(); 21 22 public bool IsOK; 23 24 public RefineSearch() 25 { 26 InitializeComponent(); 27 Title = "Refine Search" + AppContext.AppVersion; 28 Title = "Name" + AppContext.AppVersion; 29 var theImage = new BitmapImage(new Uri("MainBackground.jpg", UriKind.Relative)); 30 var myImageBrush = new ImageBrush(theImage); 31 myImageBrush.Stretch = Stretch.Fill; 32 Background = myImageBrush; 33 34 //_fieldTypes.Add(new FieldType(1, "Job File Version Number", "VersionNumber", "NonNegativeIntRange")); 35 _fieldTypes.Add(new FieldType(2, "Version Comment", "VersionComment", "string")); 36 _fieldTypes.Add(new FieldType(3, "Previous Revision", "PreviousRevision", "string")); 37 _fieldTypes.Add(new FieldType(4, "Job Revision Tag", "RevisionTag", "string")); 38 _fieldTypes.Add(new FieldType(5, "Record Created", "DateTimeRecordCreated", "DateRange")); 39 _fieldTypes.Add(new FieldType(6, "Check Out Person HalId", "CheckOutPersonHalId", "string")); 40 _fieldTypes.Add(new FieldType(7, "Check Out State", "CheckOutState", "string")); 41 _fieldTypes.Add(new FieldType(8, "Upload Person HalId", "UploadPersonHalId", "string")); 42 //_fieldTypes.Add(new FieldType(9, "File Name", "JobFileName", "string")); 43 //_fieldTypes.Add(new FieldType(10, "Parent Job Version", "ParentFileUid", "Guid")); 44 //_fieldTypes.Add(new FieldType(11, "Parent MultiJob and Version", "ParentMultiJobVersionUid", "Guid")); 45 _fieldTypes.Add(new FieldType(12, "None Editable Job", "IsFinal", "bool")); 46 _fieldTypes.Add(new FieldType(13, "Data Start Date", "DateFileStarted", "DateRange")); 47 _fieldTypes.Add(new FieldType(14, "Company Name", "CompanyName", "string")); 48 _fieldTypes.Add(new FieldType(15, "Parent Company Name", "ParentCompanyName", "string")); 49 _fieldTypes.Add(new FieldType(16, "Contract Reference Person", "ContractReference", "string")); 50 _fieldTypes.Add(new FieldType(17, "Customer Contact", "CompanyRepresentative", "string")); 51 _fieldTypes.Add(new FieldType(18, "Company City", "CompanyCity", "string")); 52 _fieldTypes.Add(new FieldType(19, "Company State", "CompanyState", "string")); 53 _fieldTypes.Add(new FieldType(20, "Company Zip Code", "CompanyZipCode", "string")); 54 _fieldTypes.Add(new FieldType(21, "Job Category", "JobCategory", "string")); 55 _fieldTypes.Add(new FieldType(22, "Job Type", "JobType", "string")); 56 _fieldTypes.Add(new FieldType(23, "Field/Block", "FieldOrBlock", "string")); 57 _fieldTypes.Add(new FieldType(24, "Lease/Installation Name", "LeaseOrInstallationName", "string")); 58 _fieldTypes.Add(new FieldType(25, "Well Name", "WellName", "string")); 59 _fieldTypes.Add(new FieldType(26, "Well Number", "WellNumber", "string")); 60 _fieldTypes.Add(new FieldType(27, "Well Country", "Country", "string")); 61 _fieldTypes.Add(new FieldType(28, "Well API Number", "WellAPINumber", "string")); 62 _fieldTypes.Add(new FieldType(29, "State/Territory", "StateOrTerritory", "string")); 63 _fieldTypes.Add(new FieldType(30, "County/Parish", "CountyOrParish", "string")); 64 _fieldTypes.Add(new FieldType(31, "Nearest City", "NearestCity", "string")); 65 _fieldTypes.Add(new FieldType(32, "Load Out Point", "LoadOutPoint", "string")); 66 _fieldTypes.Add(new FieldType(33, "AFE Number", "AFENumber", "string")); 67 _fieldTypes.Add(new FieldType(34, "Job Timing", "JobTiming", "DateRange")); 68 _fieldTypes.Add(new FieldType(35, "Proposal/Quote Due Date", "ProposalOrQuoteDueDate", "DateRange")); 69 _fieldTypes.Add(new FieldType(36, "Rig Name", "RigName", "string")); 70 _fieldTypes.Add(new FieldType(37, "Rig Type", "RigType", "string")); 71 _fieldTypes.Add(new FieldType(38, "Rig Site Contact", "RigSiteContact", "string")); 72 _fieldTypes.Add(new FieldType(39, "Top Drive", "IsTopDrive", "bool")); 73 _fieldTypes.Add(new FieldType(40, "Block Weight", "BlockWeight", "doubleRange?")); 74 _fieldTypes.Add(new FieldType(41, "Elevation From KB To Hanger", "ElevationFromKBToHanger", "doubleRange?")); 75 _fieldTypes.Add(new FieldType(42, "Off shore", "IsOffshore", "bool")); 76 _fieldTypes.Add(new FieldType(43, "Elevation From KB To Sea Level", "ElevationFromKBToMeanSeaLevel", "doubleRange?")); 77 _fieldTypes.Add(new FieldType(44, "Water Depth", "WaterDepth", "doubleRange?")); 78 _fieldTypes.Add(new FieldType(45, "Completed By", "FormCompletedBy", "string")); 79 _fieldTypes.Add(new FieldType(46, "HCT Account Rep", "HCTAccountRep", "string")); 80 //_fieldTypes.Add(new FieldType(47, "Hal Sales Office", "HalliburtonSalesOffice", "string")); 81 //_fieldTypes.Add(new FieldType(48, "Hal Operations Location", "HalliburtonOperationsLocation", "string")); 82 _fieldTypes.Add(new FieldType(49, "Service Coordinator", "ServiceCoordinator", "string")); 83 _fieldTypes.Add(new FieldType(50, "Proposal/Quote Prepared By", "ProposalOrQuotePreparedBy", "string")); 84 _fieldTypes.Add(new FieldType(51, "Is Latest Version", "IsLatestVersion", "bool")); 85 //_fieldTypes.Add(new FieldType(52, "Sales Orders", "PfgDbSalesOrders", "List<PfgDbSalesOrder>")); 86 _fieldTypes.Add(new FieldType(53, "Proposal Number", "ProposalNumber", "string")); 87 _fieldTypes.Add(new FieldType(54, "BD File Number", "BDFileNumber", "string")); 88 _fieldTypes.Add(new FieldType(55, "Option Number", "OptionNumber", "string")); 89 _fieldTypes.Add(new FieldType(56, "Purchase Number", "PONumber", "string")); 90 _fieldTypes.Add(new FieldType(57, "SAP Quote Number", "SAPQuoteNumber", "string")); 91 _fieldTypes.Add(new FieldType(58, "Sold to Number", "SoldToNumber", "string")); 92 _fieldTypes.Add(new FieldType(59, "Ship to Number", "ShipToNumber", "string")); 93 _fieldTypes.Add(new FieldType(60, "Bill to Number", "BillToNumber", "string")); 94 PopulateComboBoxes(); 95 } 96 97 private void PopulateComboBoxes() 98 { 99 _searchComboBoxes.Clear(); 100 _searchComboBoxes.Add(comboBoxSearchOption1); 101 _searchComboBoxes.Add(comboBoxSearchOption2); 102 _searchComboBoxes.Add(comboBoxSearchOption3); 103 _searchComboBoxes.Add(comboBoxSearchOption4); 104 _searchComboBoxes.Add(comboBoxSearchOption5); 105 _searchComboBoxes.Add(comboBoxSearchOption6); 106 _searchComboBoxes.Add(comboBoxSearchOption7); 107 _searchComboBoxes.Add(comboBoxSearchOption8); 108 _searchComboBoxes.Add(comboBoxSearchOption9); 109 _searchComboBoxes.Add(comboBoxSearchOption10); 110 111 PopulateComboBox(comboBoxSearchOption1); 112 PopulateComboBox(comboBoxSearchOption2); 113 PopulateComboBox(comboBoxSearchOption3); 114 PopulateComboBox(comboBoxSearchOption4); 115 PopulateComboBox(comboBoxSearchOption5); 116 PopulateComboBox(comboBoxSearchOption6); 117 PopulateComboBox(comboBoxSearchOption7); 118 PopulateComboBox(comboBoxSearchOption8); 119 PopulateComboBox(comboBoxSearchOption9); 120 PopulateComboBox(comboBoxSearchOption10); 121 } 122 123 private void PopulateComboBox(ComboBox comboBox) 124 { 125 comboBox.Items.Clear(); 126 foreach (var fieldType in _fieldTypes) 127 comboBox.Items.Add(fieldType); 128 } 129 130 private static void RepopulateComboBox(ComboBox comboBox, FieldType fieldTypeToRemove, FieldType fieldTypeToAdd) 131 { 132 if( fieldTypeToRemove != null) 133 comboBox.Items.Remove(fieldTypeToRemove); 134 if (fieldTypeToAdd != null) 135 { 136 int comboBoxItemsCount = comboBox.Items.Count; 137 int newNumber = fieldTypeToAdd.SortOrder; 138 for (int j = 0; j < comboBoxItemsCount; j++ ) 139 { 140 var testFieldType = comboBox.Items[j] as FieldType; 141 if (testFieldType == null) 142 continue; 143 if( testFieldType.SortOrder > newNumber) 144 { 145 comboBox.Items.Insert(j, fieldTypeToAdd); 146 return; 147 } 148 } 149 } 150 } 151 152 private void comboBoxSearch_SelectionChanged(object sender, SelectionChangedEventArgs e) 153 { 154 var comboBox = sender as ComboBox; 155 if (comboBox == null) 156 return; 157 var newFieldType = comboBox.SelectedItem as FieldType; 158 var list = e.RemovedItems; 159 FieldType oldFieldType = null; 160 if (list != null && list.Count > 0) 161 oldFieldType = list[0] as FieldType; 162 163 // Update the items in the other ComboBoxes 164 foreach( var testComboBox in _searchComboBoxes) 165 { 166 if (testComboBox.Name == comboBox.Name) 167 continue; 168 RepopulateComboBox(testComboBox, newFieldType, oldFieldType); 169 } 170 171 // Changed the text boxes based on if the Fieldtype DataType is: 172 // String, doubleRange?, bool, dateRange, 173 if (newFieldType == null) 174 return; 175 //if (newFieldType.DataType.ToUpper() == "STRING") 176 //{ 177 // minTextBox.Visibility = Visibility.True; 178 // maxTextBox.Visibility = Visibility.Collapsed; 179 //} 180 181 switch (comboBox.Name) //switch选择段落是我之前没用xaml的dataTenplateSelector时的方法,具体是C#检测每一次所选择的newFieldType的dataType然后做判断 182 { 183 case "comboBoxSearchOption1": 184 if (newFieldType.DataType.ToUpper() =="STRING" ) 185 { 186 textBoxSearchOption1_MaxValue.Visibility = System.Windows.Visibility.Hidden; 187 } 188 else 189 { 190 textBoxSearchOption1_MaxValue.Visibility = System.Windows.Visibility.Visible; 191 } 192 break; 193 case "comboBoxSearchOption2": 194 if (newFieldType.DataType.ToUpper() == "STRING") 195 { 196 textBoxSearchOption2_MaxValue.Visibility = System.Windows.Visibility.Hidden; 197 } 198 else 199 { 200 textBoxSearchOption2_MaxValue.Visibility = System.Windows.Visibility.Visible; 201 } 202 break; 203 case "comboBoxSearchOption3": 204 if (newFieldType.DataType.ToUpper() == "STRING") 205 { 206 textBoxSearchOption3_MaxValue.Visibility = System.Windows.Visibility.Hidden; 207 } 208 else 209 { 210 textBoxSearchOption3_MaxValue.Visibility = System.Windows.Visibility.Visible; 211 } 212 break; 213 case "comboBoxSearchOption4": 214 if (newFieldType.DataType.ToUpper() == "STRING") 215 { 216 textBoxSearchOption4_MaxValue.Visibility = System.Windows.Visibility.Hidden; 217 } 218 else 219 { 220 textBoxSearchOption4_MaxValue.Visibility = System.Windows.Visibility.Visible; 221 } 222 break; 223 case "comboBoxSearchOption5": 224 if (newFieldType.DataType.ToUpper() == "STRING") 225 { 226 textBoxSearchOption5_MaxValue.Visibility = System.Windows.Visibility.Hidden; 227 } 228 else 229 { 230 textBoxSearchOption5_MaxValue.Visibility = System.Windows.Visibility.Visible; 231 } 232 break; 233 case "comboBoxSearchOption6": 234 if (newFieldType.DataType.ToUpper() == "STRING") 235 { 236 textBoxSearchOption6_MaxValue.Visibility = System.Windows.Visibility.Hidden; 237 } 238 else 239 { 240 textBoxSearchOption6_MaxValue.Visibility = System.Windows.Visibility.Visible; 241 } 242 break; 243 case "comboBoxSearchOption7": 244 if (newFieldType.DataType.ToUpper() == "STRING") 245 { 246 textBoxSearchOption7_MaxValue.Visibility = System.Windows.Visibility.Hidden; 247 } 248 else 249 { 250 textBoxSearchOption7_MaxValue.Visibility = System.Windows.Visibility.Visible; 251 } 252 break; 253 case "comboBoxSearchOption8": 254 if (newFieldType.DataType.ToUpper() == "STRING") 255 { 256 textBoxSearchOption8_MaxValue.Visibility = System.Windows.Visibility.Hidden; 257 } 258 else 259 { 260 textBoxSearchOption8_MaxValue.Visibility = System.Windows.Visibility.Visible; 261 } 262 break; 263 case "comboBoxSearchOption9": 264 if (newFieldType.DataType.ToUpper() == "STRING") 265 { 266 textBoxSearchOption9_MaxValue.Visibility = System.Windows.Visibility.Hidden; 267 } 268 else 269 { 270 textBoxSearchOption9_MaxValue.Visibility = System.Windows.Visibility.Visible; 271 } 272 break; 273 case "comboBoxSearchOption10": 274 if (newFieldType.DataType.ToUpper() == "STRING") 275 { 276 textBoxSearchOption10_MaxValue.Visibility = System.Windows.Visibility.Hidden; 277 } 278 else 279 { 280 textBoxSearchOption10_MaxValue.Visibility = System.Windows.Visibility.Visible; 281 } 282 break; 283 } 284 285 } 286 287 private void ResetButton_Click(object sender, RoutedEventArgs e) 288 { 289 PopulateComboBoxes(); 290 } 291 292 private void SearchButton_Click(object sender, RoutedEventArgs e) 293 { 294 IsOK = true; 295 Close(); 296 } 297 } 298 299 public class dataTypeTemplateSelecter : DataTemplateSelector //使用DataTemplateSelector 的方法,在xaml文件下制作不同的dataTemplate用来切换。 300 { 301 private DataTemplate _stringDataTemplate = null; 302 public DataTemplate StringDataTemplate 303 { 304 get { return _stringDataTemplate; } 305 set { _stringDataTemplate = value; } 306 } 307 private DataTemplate _otherDataTemplate = null; 308 public DataTemplate OtherDataTemplate 309 { 310 get { return _otherDataTemplate; } 311 set { _otherDataTemplate = value; } 312 } 313 314 public override DataTemplate SelectTemplate(object item, DependencyObject container) 315 { 316 if (item is FieldType) 317 { 318 if (item.GetType().ToString().ToUpper() == "STRING") 319 { 320 return _stringDataTemplate; 321 } 322 else 323 return _otherDataTemplate; 324 } 325 return base.SelectTemplate(item, container); 326 } 327 328 } 329 }
制作完了C#后台dataTypeTemplateSelecter类后,我们就可以和前台xaml链接。
1 RefineSearch.xaml文件: 2 3 <Window 4 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 5 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 xmlns:src="clr-namespace:PfgDbTestHarness" 9 mc:Ignorable="d" 10 x:Class="PfgDbTestHarness.RefineSearch" 11 Title="Refine Search" 12 d:DesignHeight="500" 13 d:DesignWidth="754" 14 SizeToContent="WidthAndHeight" 15 Width="754" Height="500" 16 MinWidth="754" 17 MinHeight="300"> 18 <Window.Resources> 19 <ResourceDictionary> 20 <DataTemplate x:Key="stringDataTemplate" DataType="{x:Type src:FieldType}"> //dataType为string类型的dataTemplate 21 <Grid> 22 <Grid.ColumnDefinitions> 23 <ColumnDefinition/> 24 <ColumnDefinition/> 25 </Grid.ColumnDefinitions> 26 <TextBox x:Name="textBoxSearchOption_stringValue" Margin="10,4" TextWrapping="Wrap" Text="{Binding StringInput, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:LayoutOverrides="Height" Grid.Column="0"/> 27 </Grid> 28 </DataTemplate> 29 <DataTemplate x:Key="otherDataTemplate" DataType="{x:Type src:FieldType}"> //dataType为其他类型的dataTemplate 30 <Grid> 31 <Grid.ColumnDefinitions> 32 <ColumnDefinition/> 33 <ColumnDefinition/> 34 </Grid.ColumnDefinitions> 35 <TextBox x:Name="textBoxSearchOption_MinValue" Margin="10,4" TextWrapping="Wrap" Text="{Binding MinDoubleInput, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:LayoutOverrides="Height" Grid.Column="0"/> //这里是Ryan教我的时候暂时加的,其实这里我本来要表示的是其他所有类型,但是暂时先假定是double类型 36 <TextBox x:Name="textBoxSearchOption_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="{Binding MaxDoubleInput, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:LayoutOverrides="Height" Grid.Column="1"/> 37 </Grid> 38 </DataTemplate> 39 <src:dataTypeTemplateSelecter x:Key="DataTypeTemplateSelecter" 40 StringDataTemplate="{StaticResource stringDataTemplate}" 41 OtherDataTemplate="{StaticResource otherDataTemplate}"/> 42 </ResourceDictionary> 43 </Window.Resources> 44 45 <Grid x:Name="MainGrid" ShowGridLines="False"> 46 <Grid.RowDefinitions> 47 <RowDefinition Height="Auto"/> 48 <RowDefinition Height="Auto"/> 49 <RowDefinition Height="Auto"/> 50 </Grid.RowDefinitions> 51 <StackPanel Margin="5,2" Grid.Row="1"> 52 <Grid x:Name="RefineSearchTitle" Margin="0,2"> 53 <Grid.ColumnDefinitions> 54 <ColumnDefinition Width="0.5*"/> 55 <ColumnDefinition Width="0.25*"/> 56 <ColumnDefinition Width="0.25*"/> 57 </Grid.ColumnDefinitions> 58 <TextBlock TextWrapping="Wrap" Text="Refine Search Fields" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center"/> 59 <TextBlock TextWrapping="Wrap" Text="MinValue" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1"/> 60 <TextBlock TextWrapping="Wrap" Text="MaxValue" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="2"/> 61 </Grid> 62 <Grid x:Name="RefineSearchTab1" Margin="0,2"> 63 <Grid.ColumnDefinitions> 64 <ColumnDefinition Width="0.5*"/> 65 <!--<ColumnDefinition Width="0.25*"/> 66 <ColumnDefinition Width="0.25*"/>--> 67 <ColumnDefinition Width="0.5*"/> 68 </Grid.ColumnDefinitions> 69 <ComboBox x:Name="comboBoxSearchOption1" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" IsEditable="False"/> 70 <!--<TextBox x:Name="textBoxSearchOption1_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 71 <TextBox x:Name="textBoxSearchOption1_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/>--> 72
<ContentPresenter Content="{Binding ElementName=comboBoxSearchOption1, Path=SelectedItem}" 73 Margin="10,4" 74 Grid.Column="1" 75 ContentTemplateSelector="{StaticResource DataTypeTemplateSelecter}"/>
//这里是实现连接的重要部分。定义了ContentPresenter的Content和ContentTemplateSelector。 76 </Grid> 77 <Grid x:Name="RefineSearchTab2" Margin="0,2"> //下面所有的RefineSearchTabX是没用DataTypeTemplateSelecter时候的方法,后台纯C#实现切换。当选择为string的其中一个textbox的visability为false。见后台switch那部分语句
78 <Grid.ColumnDefinitions> 79 <ColumnDefinition Width="0.5*"/> 80 <ColumnDefinition Width="0.25*"/> 81 <ColumnDefinition Width="0.25*"/> 82 </Grid.ColumnDefinitions> 83 <ComboBox x:Name="comboBoxSearchOption2" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 84 <TextBox x:Name="textBoxSearchOption2_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 85 <TextBox x:Name="textBoxSearchOption2_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 86 </Grid> 87 <Grid x:Name="RefineSearchTab3" Margin="0,2"> 88 <Grid.ColumnDefinitions> 89 <ColumnDefinition Width="0.5*"/> 90 <ColumnDefinition Width="0.25*"/> 91 <ColumnDefinition Width="0.25*"/> 92 </Grid.ColumnDefinitions> 93 <ComboBox x:Name="comboBoxSearchOption3" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 94 <TextBox x:Name="textBoxSearchOption3_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 95 <TextBox x:Name="textBoxSearchOption3_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 96 </Grid> 97 <Grid x:Name="RefineSearchTab4" Margin="0,2"> 98 <Grid.ColumnDefinitions> 99 <ColumnDefinition Width="0.5*"/> 100 <ColumnDefinition Width="0.25*"/> 101 <ColumnDefinition Width="0.25*"/> 102 </Grid.ColumnDefinitions> 103 <ComboBox x:Name="comboBoxSearchOption4" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 104 <TextBox x:Name="textBoxSearchOption4_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 105 <TextBox x:Name="textBoxSearchOption4_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 106 </Grid> 107 <Grid x:Name="RefineSearchTab5" Margin="0,2"> 108 <Grid.ColumnDefinitions> 109 <ColumnDefinition Width="0.5*"/> 110 <ColumnDefinition Width="0.25*"/> 111 <ColumnDefinition Width="0.25*"/> 112 </Grid.ColumnDefinitions> 113 <ComboBox x:Name="comboBoxSearchOption5" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 114 <TextBox x:Name="textBoxSearchOption5_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 115 <TextBox x:Name="textBoxSearchOption5_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 116 </Grid> 117 <Grid x:Name="RefineSearchTab6" Margin="0,2"> 118 <Grid.ColumnDefinitions> 119 <ColumnDefinition Width="0.5*"/> 120 <ColumnDefinition Width="0.25*"/> 121 <ColumnDefinition Width="0.25*"/> 122 </Grid.ColumnDefinitions> 123 <ComboBox x:Name="comboBoxSearchOption6" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 124 <TextBox x:Name="textBoxSearchOption6_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 125 <TextBox x:Name="textBoxSearchOption6_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 126 </Grid> 127 <Grid x:Name="RefineSearchTab7" Margin="0,2"> 128 <Grid.ColumnDefinitions> 129 <ColumnDefinition Width="0.5*"/> 130 <ColumnDefinition Width="0.25*"/> 131 <ColumnDefinition Width="0.25*"/> 132 </Grid.ColumnDefinitions> 133 <ComboBox x:Name="comboBoxSearchOption7" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 134 <TextBox x:Name="textBoxSearchOption7_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 135 <TextBox x:Name="textBoxSearchOption7_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 136 </Grid> 137 <Grid x:Name="RefineSearchTab8" Margin="0,2"> 138 <Grid.ColumnDefinitions> 139 <ColumnDefinition Width="0.5*"/> 140 <ColumnDefinition Width="0.25*"/> 141 <ColumnDefinition Width="0.25*"/> 142 </Grid.ColumnDefinitions> 143 <ComboBox x:Name="comboBoxSearchOption8" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 144 <TextBox x:Name="textBoxSearchOption8_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 145 <TextBox x:Name="textBoxSearchOption8_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 146 </Grid> 147 <Grid x:Name="RefineSearchTab9" Margin="0,2"> 148 <Grid.ColumnDefinitions> 149 <ColumnDefinition Width="0.5*"/> 150 <ColumnDefinition Width="0.25*"/> 151 <ColumnDefinition Width="0.25*"/> 152 </Grid.ColumnDefinitions> 153 <ComboBox x:Name="comboBoxSearchOption9" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 154 <TextBox x:Name="textBoxSearchOption9_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 155 <TextBox x:Name="textBoxSearchOption9_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 156 </Grid> 157 <Grid x:Name="RefineSearchTab10" Margin="0,2,0,2 "> 158 <Grid.ColumnDefinitions> 159 <ColumnDefinition Width="0.5*"/> 160 <ColumnDefinition Width="0.25*"/> 161 <ColumnDefinition Width="0.25*"/> 162 </Grid.ColumnDefinitions> 163 <ComboBox x:Name="comboBoxSearchOption10" d:LayoutOverrides="Height" Margin="10,4" SelectionChanged="comboBoxSearch_SelectionChanged" /> 164 <TextBox x:Name="textBoxSearchOption10_MinValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="1"/> 165 <TextBox x:Name="textBoxSearchOption10_MaxValue" Margin="10,4" TextWrapping="Wrap" Text="" d:LayoutOverrides="Height" Grid.Column="2"/> 166 </Grid> 167 </StackPanel> 168 <Button x:Name="ResetButton" Background="Bisque" Content="Reset" Width="100" Grid.Row="2" Margin="0,14,161,0" HorizontalAlignment="Right" VerticalAlignment="Top" Height="45" FontSize="21.333" Click="ResetButton_Click" /> 169 <Button x:Name="SearchButton" Background="Bisque" Content="Search" Width="100" Grid.Row="2" Height="45" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,14,20,0" FontSize="21.333" Click="SearchButton_Click" /> 170 171 172 </Grid> 173 </Window>