This is my first question on StackOverflow. Due to the lack of reputation, I could not post links or images. I have been working on the following question for more than two days. Any help would be greatly appreciated.
Before moving on to my question, here is what I have and what I expect:
- I have a Windows Form that contains WPF in an ElementHost element .
- And then I have a Winforms UserControl similar to a DateTimePicker. This
is hosted inside a WindowsFormsHost control .
The above scenario cannot be avoided for the following reasons:
- The authorization dialog for all our applications is developed in Winforms, and takes an instance of Winforms as a parameter. There is no WPF version added. So I had to use ElementHost for host my View inside a Windows form.
- The Winforms control hosted inside my WPF can also be avoided. We have our own custom DateTime Winforms UserControl, which behaves similarly to the DateTimePicker Winforms control, but has a lot more complexity involved. Therefore, replacing this control with the WPF version is missing a question.
Expected Functionality:
I have
"" , ViewModel, RunViewModel WPF UserControl , RunView.xaml.cs.
eventAggregator.GetEvent<ResetDateTimeEvent>().Publish(true);
eventAggregator.GetEvent<ResetDateTimeEvent>().Subscribe(ResetDateTimeHandler);
WPF , DateTime UserControl reset.
, ElementHost WPF- WindowsFormsHost, UserTontrol Winforms DateTime "" WPF.
, DateTime .
, DateTime Winforms UserControl.
, DateTime Winforms UserControl Winforms . , :
WinForms-ElementHost-WPF-WindowsFormsHost-Winforms
xaml.
<WindowsFormsHost x:Name="ReportFromDtTmHost" Margin="8,0" Grid.Column="0"
LostFocus="ReportFromDtTmHost_LostFocus">
<WindowsFormsHost.Child>
<winforms:TextBox x:Name="ReportFromDateTime"/>
</WindowsFormsHost.Child>
</WindowsFormsHost>
Im Textbox Initial Load Text
private void Window_Loaded(object sender, EventArgs e)
{
ReportFromDateTime.Text = "Initial Load Text";
}
, "" , :
ViewModel
eventAggregator.GetEvent() ();.
(xaml.cs):
eventAggregator.GetEvent() (ResetDateTimeHandler);.
EventHandler .
private void ResetDateTimeHandler (bool cancelClicked)
{ ReportFromDateTime.Text = "Reset ";
}
, Im "" .
, Text "Reset ", , .
:
WindowsFormsHost TextBox ReportFromDateTime.
, Child and Name WindowsFormsHost .
Name ,
ReportFromDtTmHost.Child.Name = ""
ReportFromDateTime.
, Host Child .
, , (WinForms-ElementHost-WPF-WindowsFormsHost-Winforms Textbox) WPF Winforms.
. , . . :
" Windows Forma".
, Nesting.
, . , , , . , , - . .
, - . :
, static.
Winforms:
Winforms
public static class ControlHolder
{
public static TextBox ReportFromDateTimeInstance;
}
OnChanged "" ReportFromDateTime ReportFromDateTimeInstance.
private void ReportFromDateTime_TextChanged(object sender, EventArgs e)
{
ControlHolder.ReportFromDateTimeInstance = (TextBox)sender;
}
, ( ResetDateTimeHandler),
private void ResetDateTimeHandler(bool cancelClicked)
{
ControlHolder.ReportFromDateTimeInstance = "Text changed";
}
EventAggregator
.
ReportFromDateTime, , ControlHolder.ReportFromDateTimeInstance
/ ResetDateTimeEvent , Unity Container. ,
eventAggregator.GetEvent<ResetDateTimeEvent>.Publish(true);
:
ResetDateTimeEvent.Instance.Publish(true);
:
ResetDateTimeEvent.Instance.Subscribe(ResetDateTimeHandler);
, , , Unity Container ( , ViewModels), .
, , . -ness, ?
, , , , , .
.