简体   繁体   中英

WPF custom control child controls lose binding

I created a WPF custom paging control, and added buttons to them and i am show/hiding the same depending upon the no of records.

Now, the control perfectly works for the first time. But, when it is unloaded and then loaded back again, then all the controls seem to lose their bindings.

In the OnApplyTemplate method, i am using the following code to initialize the buttons:

radioBtnIndex1 = this.Template.FindName("PART_IndexButton1", this) as RadioButton;

And, also, i have created a dependency property as follows:

TotalRecordsProperty = DependencyProperty.Register("TotalRecords", typeof(uint), typeof(PagingControl), new PropertyMetadata(OnTotalRecordsChanged));

In the OnTotalRecordsChanged method, i am changing the visibility of the button as:

radioBtnIndex1.Visibility = Visibility.Collapsed;

This works like a charm for the first time, but not when i navigate away from my view, and come back. ie not after once the control has been unloaded and then loaded again.

The radioBtnIndex1 is a static variable.

Can someone provide any thoughts on this

Since I have not saw your entire code, I'm not sure where the issue was. So if you could share a repro code sample with us. It would be useful to locate this issue in my side. You can upload repro code sample and post link here.

I would help you test it in my side.

If you cannot share your total code with us. You could refer to the following code sample. You can compare it with your code. Maybe, you would find some issues in your code.

Here's a small paging control for WPF app, you could refer to it for details: Small Paging Control for Windows Presentation Foundation (WPF)

This is a opensource control: XAML Paging & Sorting Control

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM