2013-02-06 157 views
0

我有类:如何更新样式的内容?

class NoExp : Expander 
{ 
    public long Id { get; set; } 
    public string btnBackGround { get;set;} 
    public bool btnEnabled { get; set; } 
    public string btnForeground { get; set; } 
    public string tbText { get; set; } 
    public string tbTime { get; set; } 
    public string tbNumber { get; set; } 
    public string tbForeground { get; set; } 
    public ServiceReference.PickerItemItem[] DGItemSource { get; set; }} 

和样式:

<Style x:Key="ExpanderStyle" TargetType="{x:Type local:NoExp}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type local:NoExp}"> 
        <Grid> 
         <Button Content="Собран" Height="35.5" Margin="5,0,1,0" VerticalAlignment="Top" 
           Foreground="{Binding btnForeground, RelativeSource={RelativeSource TemplatedParent}}" 
           Background="{Binding btnBackGround, RelativeSource={RelativeSource TemplatedParent}}" 
           IsEnabled="{Binding btnEnabled, RelativeSource={RelativeSource TemplatedParent}}" 
           Tag="{Binding Id, RelativeSource={RelativeSource TemplatedParent}}" 
           Style="{DynamicResource ButtonStyle1}" Click="Button_Click_1"/> 

在代码中,我试图改变:

foreach (NoExp exp in listBox.Items) 
       { 
        exp.btnForeground = "#808080"; 
       } 

数据的变化,但在界面上没有变化。请告诉我应该怎么做。

+0

分配风格忘了。当创建一切工作,因为它应该。更新出现问题。 – Kirill

回答

0

你看过处理可观察集合吗?

当设置属性时,您的实体需要继承INotifyPropertyChanged并调用NotifyPropertyChanged。假设你的实体对象包含在一个ObservableCollection中,你的控件绑定到所有东西都会更新。

我在Silverlight中成功地在PivotViewer中使用了它。

了解更多: Silverlight Databinding – The Observable Collection

+0

它的工作原理!谢谢! – Kirill