简体   繁体   English

Windows Phone侧边栏WP8 xaml中的自定义标题

[英]Custom header in sidebar WP8 xaml in windows phone

My scenario is: I want a custom header which contains an image and a header title(text) dynamically by data context or the best way it can be done as in my image: 我的情况是:我想要一个自定义标头,其中包含一个图像和一个标头标题(文本),该标头通过数据上下文或它可以像在我的图像中一样的最佳方式动态地动态显示: 在此处输入图片说明

Main page Xaml.cs: 主页Xaml.cs:

 <sidebar:SidebarControl x:Name="sidebarControl" 
                            HeaderBackground="#8E8E93"
                            HeaderForeground="White"
                            SidebarBackground="#ffffff" DataContext="{Binding d}">
        <sidebar:SidebarControl.HeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Image Margin="5" Source="{Binding Path=ImageSource}" Width="48" Height="48"/>
                    <TextBlock Foreground="Red" Text="{Binding Path=Name}" Width="200"></TextBlock>
                </StackPanel>
            </DataTemplate>
        </sidebar:SidebarControl.HeaderTemplate>

        <sidebar:SidebarControl.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="#FF9DA3AE" Offset="1"/>
            </LinearGradientBrush>
        </sidebar:SidebarControl.Background>
        <sidebar:SidebarControl.SidebarContent>

            <StackPanel></StackPanel>
        </sidebar:SidebarControl.SidebarContent>

    </sidebar:SidebarControl>

My .CS file code, please take a look and let me know how to fix it 我的.CS文件代码,请看一看,让我知道如何解决它

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using sidebar.Resources;

namespace sidebar
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Demo d = new Demo() { Name = "Custom Header", ImageSource = "/Assets/Images/Favorite.png" };
            sidebarControl.DataContext = d;
        }
    }
    public class Demo
    {
        public string Name { get; set; }
        public string ImageSource { get; set; }
    }
}

Replace next code 替换下一个代码

<StackPanel Orientation="Horizontal">
                    <Image Margin="5" Source="{Binding Path=ImageSource}" Width="48" Height="48"/>
                    <TextBlock Foreground="Red" Text="{Binding Path=Name}" Width="200"></TextBlock>
                </StackPanel>

with next modification: 下一个修改:

<StackPanel Orientation="Horizontal">
                    <Image Margin="5" Source="{Binding ImageSource}" Width="48" Height="48"/>
                    <TextBlock Foreground="Red" Text="{Binding Name}" Width="200"></TextBlock>
                </StackPanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM