ComponentOne 2011 v3版本中新增了Silverlight版本和WPF版本的c1OutlookBar控件。它对应的是WinForms版本的C1NavBar。因为“OutlookBar”更贴切也更准确,所以我们在XAML平台下使用了这个名字。有Outlook2007和2010样式。
OutlookBar类似一个TabControl,用户可以选择Content panel中的任何一个Item。你可以按照优先级为它们建立分类。OutlookBar可以通过拖拽操作,自由的收起或者展开各个项目。这样用户就可以方便的定制那些项目显示出来,哪些最小化到底部的菜单里。如图所示:
整个控件可以最小化到最左边或者最右边。当你不需要导航栏的时候,可以轻松的隐藏它,而将有限的屏幕空间用于显示其他UI。
C1OutlookBar支持14种不同的外观样式。其实基本上所有的ComponentOne Studio的控件都可以通过设置几个Brush属性来适应各种样式风格。这都要感谢ClearStyle技术。
控件结构
以一个最基本的例子来说,我们可以通过几行简单的XAML代码创建一个C1OutlookBar。每一个Item包含4个主要属性:Header,Content,LargeIcon以及SmallIcon。如下图所示:
此外,还需要指定哪些内容在控件收起的时候可以显示,这可以通过定义icon templates实现。下面的XAML代码是上图C1OutlookBar的全部代码:
1 <c1:C1OutlookBar Name="c1OutlookBar1" Expanded;170" IsExpanded="True" > 2 3 4 5 6 7 8 9 10 11 12 13 <!-- content shown when the bar is collapsed --> 14 15 16 17 18 19 20 21 22 23 24 25 <c1:C1OutlookBar.CollapsedContent> 26 27 28 29 30 31 32 33 34 35 36 37 <c1:C1LayoutTransformer> 38 39 40 41 42 43 44 45 46 47 48 49 <c1:C1LayoutTransformer.LayoutTransform> 50 51 52 53 54 55 56 57 58 59 60 61 <RotateTransform Angle="270" /> 62 63 64 65 66 67 68 69 70 71 72 73 </c1:C1LayoutTransformer.LayoutTransform> 74 75 76 77 78 79 80 81 82 83 84 85 <TextBlock FontSize="13" TextAlignment="Center" VerticalAlignment="Center" 86 87 88 89 90 91 92 93 94 95 96 97 Text="Navigation Pane" /> 98 99 100 101 102 103 104 105 106 107 108 109 </c1:C1LayoutTransformer> 110 111 112 113 114 115 116 117 118 119 120 121 </c1:C1OutlookBar.CollapsedContent> 122 123 124 125 126 127 128 129 130 131 132 133 <!-- define icon templates --> 134 135 136 137 138 139 140 141 142 143 144 145 <c1:C1OutlookBar.LargeIconTemplate> 146 147 148 149 150 151 152 153 154 155 156 157 <DataTemplate> 158 159 160 161 162 163 164 165 166 167 168 169 <Image Source="{Binding}" ;24" Height="24" /> 170 171 172 173 174 175 176 177 178 179 180 181 </DataTemplate> 182 183 184 185 186 187 188 189 190 191 192 193 </c1:C1OutlookBar.LargeIconTemplate> 194 195 196 197 198 199 200 201 202 203 204 205 <c1:C1OutlookBar.SmallIconTemplate> 206 207 208 209 210 211 212 213 214 215 216 217 <DataTemplate> 218 219 220 221 222 223 224 225 226 227 228 229 <Grid Height="24"> 230 231 232 233 234 235 236 237 238 239 240 241 <Image Source="{Binding}" ;16" Height="16" /> 242 243 244 245 246 247 248 249 250 251 252 253 </Grid> 254 255 256 257 258 259 260 261 262 263 264 265 </DataTemplate> 266 267 268 269 270 271 272 273 274 275 276 277 </c1:C1OutlookBar.SmallIconTemplate> 278 279 280 281 282 283 284 285 286 287 288 289 <!-- items --> 290 291 292 293 294 295 296 297 298 299 300 301 <c1:C1OutlookItem Header="Home" SmallIcon="Images/16/Home.png" LargeIcon="Images/24/Home.png"> 302 303 304 305 306 307 308 309 310 311 312 313 <TextBlock Text="My Home" /> 314 315 316 317 318 319 320 321 322 323 324 325 </c1:C1OutlookItem> 326 327 328 329 330 331 332 333 334 335 336 337 <c1:C1OutlookItem Header="Files" SmallIcon="Images/16/Cab1.png" LargeIcon="Images/24/Cab1.png"> 338 339 340 341 342 343 344 345 346 347 348 349 <TextBlock Text="My Files" /> 350 351 352 353 354 355 356 357 358 359 360 361 </c1:C1OutlookItem> 362 363 364 365 366 367 368 369 370 371 372 373 <c1:C1OutlookItem Header="Sales" SmallIcon="Images/16/ChartPie.png" LargeIcon="Images/24/ChartPie.png"> 374 375 376 377 378 379 380 381 382 383 384 385 <TextBlock Text="My Sales" /> 386 387 388 389 390 391 392 393 394 395 396 397 </c1:C1OutlookItem> 398 399 400 401 402 403 404 405 406 407 408 409 <c1:C1OutlookItem Header="History" SmallIcon="Images/16/History.png" LargeIcon="Images/24/History.png"> 410 411 412 413 414 415 416 417 418 419 420 421 <TextBlock Text="My History" /> 422 423 424 425 426 427 428 429 430 431 432 433 </c1:C1OutlookItem> 434 435 436 437 438 439 440 441 442 443 444 445 <c1:C1OutlookItem Header="Settings" SmallIcon="Images/16/User.png" LargeIcon="Images/24/User.png"> 446 447 448 449 450 451 452 453 454 455 456 457 <TextBlock Text="My Settings" /> 458 459 460 461 462 463 464 465 466 467 468 469 </c1:C1OutlookItem> 470 471 472 473 474 475 476 477 478 479 480 481 </c1:C1OutlookBar> 482 483 484 485 486 487 488 489 490 491 492 493
页面排布
当C1OutlookBar收起的时候,中间的content区域会自动展开,充满空余的界面。尤其是当把C1OutlookBar放在Grid中时,ColumnDefinition的宽度设置为Auto时,该功能支持的很好。同时初始化ExpandedWidth也很重要,当然了,这个属性可以在runtime修改。代码如下:
1 <Grid x:Name="LayoutRoot"> 2 3 4 5 6 7 8 9 10 11 12 13 <Grid.ColumnDefinitions> 14 15 16 17 18 19 20 21 22 23 24 25 <ColumnDefinition ;Auto" /> 26 27 28 29 30 31 32 33 34 35 36 37 <ColumnDefinition /> 38 39 40 41 42 43 44 45 46 47 48 49 </Grid.ColumnDefinitions> 50 51 52 53 54 55 56 57 58 59 60 61 <c1:C1OutlookBar Expanded;200" IsExpanded="True" /> 62 63 64 65 66 67 68 69 70 71 72 73 </Grid> 74 75 76 77 78 79 80 81 82 83 84 85
工作在MVVM模式下
C1OutlookBar是一个ItemsControl。我们可以将ItemsSource设置给一个由ViewModel定义的列表。这种用例下,我们还可以设置ItemTemplate,ContentTemplate。LargeIconTemplate以及SmallIconTemplate。
关于更多的功能可以下载: Studio for Silverlight或Studio for WPF。
本文出自 “葡萄城控件博客” 博客,请务必保留此出处http://powertoolsteam.blog.51cto.com/2369428/748550




