我正在尝试使用Silverlight Toolkit Control(ExpanderView)。要编辑扩展器查看器的标头,我使用ExpanderTemplate,如下所示:
<toolkit:ExpanderView.ExpanderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,10">
<Image Source="Images/List.png" Width="30" VerticalAlignment="Center" />
<TextBlock Margin="30,0,0,0" FontSize="25" FontWeight="Bold"
Foreground="#00A7D4" Text="Elite Plan"
VerticalAlignment="Center"
FontFamily="/DU;component/Fonts/Fonts.zip#Co Headline Light" />
</StackPanel>
</DataTemplate>
</toolkit:ExpanderView.ExpanderTemplate>
此模板相同,无论是否扩展了控件。
我需要在项目展开后更改模板(更改文本颜色,更改图像等)。
这可能吗?
答案 0 :(得分:0)
是的,您可以通过创建自定义属性
来实现在MainPage.xaml
中<toolkit:ExpanderView.ExpanderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,10">
<Image Name="imgExpander" Width="50" Height="50" Margin="20,0,0,0">
<Image.Source>
<BitmapImage UriSource="{Binding Path=ImageUrl,Mode=TwoWay}" />
</Image.Source>
</Image>
<TextBlock Margin="30,0,0,0" FontSize="25" FontWeight="Bold"
Foreground="#00A7D4" Text="Elite Plan"
VerticalAlignment="Center"
FontFamily="/DU;component/Fonts/Fonts.zip#Co Headline Light" />
</StackPanel>
</DataTemplate>
</toolkit:ExpanderView.ExpanderTemplate>
在MainPage.xaml.cs
中public MainPage() {
InitializeComponent();
List<CustomPizza> customPizzas = new List<CustomPizza>() {
new CustomPizza() {
Name = "Custom Pizza 1",
DateAdded = new DateTime(2010, 7, 8),
ImageUrl=new Uri("Images/Right-Arrow.jpg", UriKind.Relative),
Options = new List<PizzaOption> {
new PizzaOption() { Name = "Ham" },
new PizzaOption() { Name = "Mushrooms" },
new PizzaOption() { Name = "Tomatoes" }
}
}
};
}
private void expandes_click(object sender, RoutedEventArgs e) {
customPizza.IsExpanded = true;
customPizza.ImageUrl = new Uri("Images/Down-Arrow.jpg", UriKind.Relative);
}
public class CustomPizza : INotifyPropertyChanged
{
public string Name { get; set; }
public DateTime DateAdded { get; set; }
public IList<PizzaOption> Options { get; set; }
public bool HasNoOptions {
get {
return this.Options == null || this.Options.Count == 0;
}
}
private bool isExpanded;
public bool IsExpanded {
get { return this.isExpanded; }
set {
if (this.isExpanded != value) {
this.isExpanded = value;
this.OnPropertyChanged("IsExpanded");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName) {
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null) {
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
private Uri imageUrl;
public Uri ImageUrl {
get { return imageUrl; }
set {
if (imageUrl != value) {
imageUrl = value;
OnPropertyChanged("ImageUrl");
}
}
}
}
public class PizzaOption
{
public string Name { get; set;}
}