Silverlight数据控件与文件访问全解析
立即解锁
发布时间: 2025-08-26 01:40:55 阅读量: 5 订阅数: 20 

### Silverlight数据控件与文件访问全解析
#### 1. PivotViewer的使用
PivotViewer是一个功能强大的数据展示控件,在使用它之前,我们需要进行一系列的设置。
##### 1.1 定义PivotViewer
首先,要使用PivotViewer,需要添加对`System.Windows.Controls.Pivot.dll`程序集的引用,并将前缀映射到相应的命名空间。示例代码如下:
```xml
<UserControl x:Class="DataControls.PivotViewerTest" xmlns:pv=
"clr-namespace:System.Windows.Controls.Pivot;assembly=System.Windows.Controls.Pivot"
... >
```
然后,将PivotViewer添加到页面:
```xml
<pv:PivotViewer x:Name="pivotViewer">
</pv:PivotViewer>
```
##### 1.2 数据模板
为了定义PivotViewer为每个项目显示的内容,需要使用数据模板。这里使用的是`PivotViewerItemTemplate`类,它继承自`DataTemplate`并添加了`MaxWidth`属性,可用于设置数据项缩放大小的上限。示例代码如下:
```xml
<pv:PivotViewer x:Name="pivotViewer">
<pv:PivotViewer.ItemTemplates>
<pv:PivotViewerItemTemplate>
<Border Margin="5" BorderThickness="1" BorderBrush="SteelBlue" Width="125"
CornerRadius="4">
<Grid Margin="3">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold"
Text="{Binding Path=ModelNumber}"></TextBlock>
<TextBlock Grid.Row="1" Text="{Binding Path=ModelName}"></TextBlock>
<Image MinHeight="100" Grid.Row="2" Grid.RowSpan="2" Source=
"{Binding Path=ProductImagePath, Converter={StaticResource ImagePathConverter}}">
</Image>
</Grid>
</Border>
</pv:PivotViewerItemTemplate>
</pv:PivotViewer.ItemTemplates>
</pv:PivotViewer>
```
##### 1.3 透视属性
若要使用PivotViewer的过滤窗格和详细信息窗格,需要添加透视属性。每个属性映射到数据项中的单个字段,告诉PivotViewer如何使用该信息。
定义透视属性时,需要填充`PivotViewer.PivotProperties`集合。例如,映射普通字符串(如类别名称),可添加`PivotViewerStringProperty`:
```xml
<pv:PivotViewer x:Name="pivotViewer" ItemDoubleClick="pivotViewer_ItemDoubleClick">
<pv:PivotViewer.PivotProperties>
<pv:PivotViewerStringProperty Id="CategoryName" DisplayName="Category"
Binding="{Binding CategoryName}" />
</pv:PivotViewer.PivotProperties>
...
</pv:PivotViewer>
```
每个透视属性需要提供三个关键细节:唯一的`Id`、`DisplayName`和`Binding`。若要启用过滤功能,需要添加`Options`属性:
```xml
<pv:PivotViewerStringProperty Id="CategoryName" DisplayName="Category"
Binding="{Binding CategoryName}" Options="CanFilter" />
```
`Options`属性支持多个值,如`Private`、`WrappingText`和`CanSearchText`,可以用逗号组合多个值。
PivotViewer还支持对数字数据类型和日期的专门过滤,需要使用`PivotVieweverNumericProperty`或`PivotViewerDateTimeProperty`:
```xml
<pv:PivotViewerNumericProperty Id="UnitCost" DisplayName="Cost"
Binding="{Binding UnitCost}" Format="C" Options="CanFilter" />
<pv:PivotViewerDateTimeProperty Id="DateP
```
0
0
复制全文
相关推荐










