[英]Custom header in sidebar WP8 xaml in windows phone
我的情况是:我想要一个自定义标头,其中包含一个图像和一个标头标题(文本),该标头通过数据上下文或它可以像在我的图像中一样的最佳方式动态地动态显示:
主页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>
我的.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; }
}
}
替换下一个代码
<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>
下一个修改:
<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.