I have class:
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; }}
And Style:
<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"/>
In the code I am trying to change:
foreach (NoExp exp in listBox.Items)
{
exp.btnForeground = "#808080";
}
Data changes, but no changes on the interface. Please tell me what to do.
Have you looked at working with observable collections?
Your entity would need to inherit INotifyPropertyChanged and call NotifyPropertyChanged when the property is set. Assuming your entity objects are contained in an ObservableCollection which your control is bound to everything will update fine.
I use this in Silverlight against a PivotViewer successfully.
Read more:
Silverlight Databinding – The Observable Collection