2

我正在尝试使用 Silverlight 工具包控件 (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>

这个模板是一样的,控件是否展开。

项目展开后,我需要更改模板(更改文本颜色、更改图像等)

那可能吗?

4

1 回答 1

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;}
}
于 2014-04-14T13:08:13.937 回答