2

我試圖使用Silverlight工具包控件(ExpanderView)。要編輯擴展觀衆的頭我用的是ExpanderTemplate這樣的:ExpanderView,自定義nonExpanded標題(Windows Phone)

<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

是的,你可以做到這一點通過創建一個自定義屬性

在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;} 
} 
+0

我希望你明白同樣你可以做它改變文本的顏色 – Mahesh 2014-04-14 13:09:56