Reputation: 5805
I have a windows form application and one of the control on the form is WPF user control. I have put element host control on the windows form and this is loading my user control at startup.
What I want is to load and refresh user control at certain time. As I need fresh data to be loaded.
I have tried elementHost1.Refresh();
and this is not doing anything.
How can I load and refresh this?
This is my user control on this LINK
Upvotes: 1
Views: 23945
Reputation: 13723
Make data provider re-read its source:
var dataprovider = (System.Windows.Data.XmlDataProvider) (
((UserControl1) (elementHost1.Child)).Resources ["rssData"]
);
dataprovider.Refresh ();
Upvotes: 2
Reputation: 13723
As your Control is not refreshed automatically, I assume that you do not use data binding, which might be the best solution.
Suppose you have a user control with (custom) type UserControl1 hosting a button named MyButton.
You could either create a new WPF control and assign it to the child element, e.g.
((UserControl1) (elementHost1.Child)).MyButton = new System.Windows.Button ()
or you access the WPF control as follows
var wpfButton = ((UserControl1) (elementHost1.Child)).MyButton;
and then simply reset the necessary properties of the WPF control:
wpfButton.Content = "My new text";
EDIT: Mistakes corrected.
Upvotes: 0
Reputation: 6260
What about MVVM
and INotifyPropertyChanged
?
Using INotifyPropertyChanged
you can notify View when data has been changed and refresh it in this way. Seems like this is what you want.
Take a look into couple related links:
Upvotes: 0
Reputation: 12255
What happens when you call your load event again?
Or at least the methods you are using to populate your data in the form>
i.e. either call your this.Load(null,null)
(or pass some objects or events as needed)
private void form1_load(object o, EventArgs e)
{
BindDataToControlMethod();
}
or have your code refactored so you can just call your BindDataToControlMethod()
method(s).
The elementHost1.Refresh()
call you are making just redraws the form on the screen. It does not reload per se.
Upvotes: 0