<Expander Header="{Binding CustomerName}" IsExpanded="False" HorizontalAlignment="Left" Margin="10,10,0,0" Name="expander1" VerticalAlignment="Top" Background="Wheat" Width="470" > <Border BorderBrush="Black" BorderThickness="1" > <StackPanel Height="300" Width="470"/ > </Border ></Expander >
public class Customer : INotifyPropertyChanged{ public int ID { get; set; } public string CustomerName { get; set; } public event PropertyChangedEventHandler PropertyChanged;}
Customer customer = new Customer {ID = 1, CustomerName = "Tony John"}; expander1.DataContext = customer;
<Window.Resources gt; <SolidColorBrush x:Key="ExpandarBGColor" Color="Wheat" /> <System:String x:Key="CustomerName">Tony John</Window.Resources >
< Expander Background="{StaticResource ExpandarBGColor}" Header="{StaticResource CustomerName}" Width="470" ></Expander >
< XmlDataProvider x:Key="Customers1" XPath="/Customers" > < x:XData > lt;Customers gt; <Customer id="1" name="tony"/> <Customer id="2" name="anil"/> <Customer id="3" name="pk"/> </Customers > </x:XData ></XmlDataProvider >< ListBox Width="248" Height="56" ItemsSource="{Binding Source={StaticResource Customers1},XPath=Customer/@id}" ></ListBox >
Customer customer = new Customer { ID = 1, CustomerName = "Tony 123 John" }; Binding binding = new Binding("CustomerName"); binding.Source = customer; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; txtBox1.SetBinding(TextBlock.TextProperty, binding);