c# - 为每个数据透视项标题分配一个图像

标签 c# .net xaml windows-phone

我正在尝试为我的每个数据透视项的标题分配一个图像而不是 Text 。

我尝试了几种方法(一个是这篇文章给出的 http://social.msdn.microsoft.com/Forums/wpapps/en-US/e7b5fd17-3465-4a94-81af-5c056c992c11/add-image-to-pivot-title?forum=wpdevelop )

我设法为我的枢轴分配了相同的图像,但没有为每个标题分配一个图像。

这是我试过的:

 <phone:Pivot.HeaderTemplate  >
                    <DataTemplate>

                        <Image Source="21.jpg"  Height="55" Width="55"/>

                    </DataTemplate>
                </phone:Pivot.HeaderTemplate>

这显然为每个标题提供了相同的图像,

所以我想尝试这样的事情:

<phone:Pivot.HeaderTemplate  >
                    <DataTemplate>

                        <Image Source="{Binding}"  Height="55" Width="55"/>

                    </DataTemplate>
                </phone:Pivot.HeaderTemplate>


[...]




  <phone:PivotItem    ???  >


  <// phone:PivotItem  >

但是我不知道要添加什么我的图像路径。

当我想将文本指定为标题时,我使用了这种方法并且它起作用了:

  <phone:Pivot.HeaderTemplate  >
                    <DataTemplate>
                       <TextBlock Text="{Binding }" FontSize="88"  />


                    </DataTemplate>
                </phone:Pivot.HeaderTemplate>



  <phone:PivotItem    Header = "Title1"      />

我如何为每个页眉分配图像?

最佳答案

您应该能够简单地在页眉中提供图片来源:

<phone:PivotItem Header = "21.jpg" />

这会设置用于该特定项目的 HeaderTemplate 的数据上下文。

关于c# - 为每个数据透视项标题分配一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21126182/

相关文章:

c# - View 序列化时链接中断

c# - 我如何阅读谷歌的定义部分?

c# - 在 ScrollViewer SL4 的焦点更改时将控件引入 ViewPort

c# - .NET 对象大小

c# - 通用工作计划。将文件从 FileOpenPicker 复制到本地存储

c# - 有没有办法从 C# WPF 应用程序中刷新 DNS 缓存? (在 XP、Vista、Win7 上)

c# - 安装项目在安装过程中不创建文件系统文件夹

c# - WebBrowser 控件和 JavaScript 错误

wpf - 从 ItemTemplate 中绑定(bind)到 ItemsControl 的 DataContext

c# - 使用 CanUserAddRows 为 DataGrid 的新行设置样式