[英]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.