WPF ItemsControl:- Changes Property of Items inside ItemControle after ItemSource Property of ItemsControl being changed at Run-Time?

There's no need of a INotifyPropertyChanged interface on a derived object from DependencyObject. You should use DependencyProperty instead It is not a good practice to change the whole ObservableCollection, so create one and don't destroy it: clear instead It's a wrong practice to access the items hosted inside an ItemsControl (more in general anything inside the visual tree). Within the button click handler just write the following: Button btn = (Button)e.

OriginalSource; PageNumber pn = (PageNumber)btn. DataContext; this. CurrentPage = pn.

Page However, you MUST add a new property named "Page" (type "int") in the PageNumber class To control the button color, I'd use a converter for a MultiBinding public class ButtonColorConverter : IMultiValueConverter { public object Convert(object values, Type targetType, object parameter, CultureInfo culture) { int current = (int)values0; int button = (int)values1; return button == current? Brushes. NavajoWhite : Brushes.XXX; //set the desired color } public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } However, the XAML must be changed accordingly: ItemsControl.

ItemTemplate> //specify the converter seen above.

There's no need of a INotifyPropertyChanged interface on a derived object from DependencyObject. You should use DependencyProperty instead. It is not a good practice to change the whole ObservableCollection, so create one and don't destroy it: clear instead.It's a wrong practice to access the items hosted inside an ItemsControl (more in general anything inside the visual tree).

Within the button click handler just write the following: Button btn = (Button)e. OriginalSource; PageNumber pn = (PageNumber)btn. DataContext; this.

CurrentPage = pn. Page; However, you MUST add a new property named "Page" (type "int") in the PageNumber class.To control the button color, I'd use a converter for a MultiBinding. Public class ButtonColorConverter : IMultiValueConverter { public object Convert(object values, Type targetType, object parameter, CultureInfo culture) { int current = (int)values0; int button = (int)values1; return button == current?

Brushes. NavajoWhite : Brushes. XXX; //set the desired color } public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } However, the XAML must be changed accordingly: //specify the converter seen above I didn't test the program, but it should work.

Cheers.

I will click on nextButton than how could I get DataContext of It...as you have suggest to put following code in Click eventButton btn = (Button)e. OriginalSource; PageNumber pn = (PageNumber)btn. DataContext; this.

CurrentPage = pn. Page;............Thank you so much for answering – Aryan SuryaWansi Jul 21 at 11:53 ,,,thank you so much for answering.....btw is there any way to pass background color of particular button from window to Convertor e.g. ButtonColorConverter.......Thanks..... – Aryan SuryaWansi Jul 21 at 12:28 It is not so simple. You may declare a SolidColorBrush within the Window.

Resources, then use it both for the "next" button and the converter. To do this, add a ConverterParameter="{StaticResource yourbrush}" to the MultiBinding element. Within the converter class, you may get the brush by casting the "parameter" argument to a Brush.

– Mario Vernari Jul 21 at 12:46.

As per Mario's suggestion I have use one convertor and it's working fine. Have a look at below code. Which working fine as per my requirment... Thanks Mario.MainWindow.

Xaml MainWindow.Xaml. Cs using System; using System.Collections. Generic; using System.

Linq; using System. Text; using System. Windows; using System.Windows.

Controls; using System.Windows. Data; using System.Windows. Documents; using System.Windows.

Input; using System.Windows. Media; using System.Windows.Media. Imaging; using System.Windows.

Navigation; using System.Windows. Shapes; using System.Collections. ObjectModel; using System.

ComponentModel; using System. Globalization; namespace CurrentPageProblem { /// /// Interaction logic for MainWindow. Xaml /// public partial class MainWindow : Window { ObservableCollection pageCollection = new ObservableCollection(); public MainWindow() { InitializeComponent(); pageCollection.

Add(new PageNumber(" 0 ")); pageCollection. Add(new PageNumber(" 1 ")); pageCollection. Add(new PageNumber(" 2 ")); pageCollection.

Add(new PageNumber(" 3 ")); pageCollection. Add(new PageNumber(" 4 ")); pageCollection. Add(new PageNumber(" 5 ")); this.

DataContext = this; } public ObservableCollection PageCollection { get { return this. PageCollection; } set { this. PageCollection = value; } } private int currentPage; public int CurrentPage { get { return currentPage; } set { currentPage = value; } } private void button1_Click(object sender, RoutedEventArgs e) { #region -- THIS CODE WORKS FINE NOW -- pageCollection.Clear(); pageCollection.

Add(new PageNumber(" 0 ")); pageCollection. Add(new PageNumber(" 1 ")); pageCollection. Add(new PageNumber(" 2 ")); pageCollection.

Add(new PageNumber(" 3 ")); pageCollection. Add(new PageNumber(" 4 ")); pageCollection. Add(new PageNumber(" 5 ")); pageCollection.

Add(new PageNumber(" 6 ")); pageCollection. Add(new PageNumber(" 7 ")); pageCollection. Add(new PageNumber(" 8 ")); pageCollection.

Add(new PageNumber(" 9 ")); #endregion currentPage++; } } public class ButtonColorConverter : IMultiValueConverter { public object Convert(object values, Type targetType, object parameter, CultureInfo culture) { string current = string. Format(" {0} ", values0); string button = (string)values1; return button == current?Brushes. NavajoWhite : Brushes.

White; //set the desired color } public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class PageNumber { private string page_Number; public PageNumber(string pageNumberArg) { this. Page_Number = pageNumberArg; } public string Page_Number { get { return page_Number; } set { page_Number = value; } } } }.

There's no need of a INotifyPropertyChanged interface on a derived object from DependencyObject. You should use DependencyProperty instead.

As per Mario's suggestion I have use one convertor and it's working fine. Have a look at below code. Which working fine as per my requirment...

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions