Hello Experts,
I am facing issue with Dialog control, when i try to put user control inside dialoghost.dialogcontent, the constructor of that UC is not getting called.
Please follow this link : StackOverflow
Here is the issue :
I've on window and one user control. I was able to run the dialog and open user control inside it, but the problem is I've listbox inside user control which is getting populate on constructor of user control, (Caliburn Micro - MVVM).
The user control works fine and gets populated if i run it stand alone, but when i put it inside DialogHost it does not work.
I am not able to figure out that it is a limitation of Dialog control that it does not support real time population or not.
Please open that link for exact same coding what I did for this issue.
Try ObservableCollection<> instead of a List<>
Hello Jespersh, i will try that.
Hello I tried binding listbox to ObservableCollection but still it does not work. And again as i said when i run User Control directly it does work and i can see the items in the list, but idk why its not working inside dialoghost.
private ObservableCollection<string> _mylist = new ObservableCollection<string>();
public ObservableCollection<string> MyList
{
get { return _mylist; }
set
{ _mylist = value; NotifyOfPropertyChange(() => MyList);} }
<ListBox x:Name="MyList" Grid.Column="1" Grid.Row="2"></ListBox>
<materialDesign:DialogHost.DialogContent>
--I am displaying my dialog here.
</materialDesign:DialogHost.DialogContent>
Does any one know how to resolve this.
Please help @Keboo
@infirazor Can you post a project that reproduces the problem? It is very difficult to say just from that information. I suspect the problem is Caliburn.Micro.
@Keboo
Hello I've uploaded a demo project to show you issue while loading content in user control inside dialog host.
https://github.com/infirazor/DialogHostIssue
Please check this and let me know anything else is needed.
I don't see you're doing any Content binding here:
https://github.com/infirazor/DialogHostIssue/blob/master/DialogHostIssue/Views/DemoWithContentView.xaml#L27
You'll need to bind it like this (for example, roughly in DemoWithContentViewModel.cs):
public UsrControlView BoundView { get; set; }
public DemoWithContentViewModel()
{
BoundView = new UsrControlView
{
DataContext = new UsrControlViewModel()
};
}
In DemoWithContentView.xaml
<ContentControl Grid.Row="2" x:Name="ActiveItem" Content="{Binding BoundView}"/>
And then I see you haven't bound any further in, so I just added this in UsrControlView.xaml to see the DataContext in done
<ComboBox x:Name="NewCustomers" Width="200" ItemsSource="{Binding Customers}"/>

@infirazor Thank you for the sample. First of all I am not very familiar with the inner workings of Caliburn.Micro (I tend to avoid it, but that is a different discussion).
First, the DialogHost internally displays its content in a Popup control. So the XAML that you put inside of the DialogContent is not actually part of the same visual tree (I suspect this is likely contibuting to the problems). So when you toggle the IsDialogOpen property, it is merely toggling the IsOpen property on that internal Popup control. Which does not leave a lot of opportunities for Caliburn.Micro to wire up all of its magic.
After digging through the WindowManager.ShowPopup method I would suggest changing up the way you are interacting with the DialogHost, and use the static Show methods. Something like this:
C#
public async Task OpenDialog()
{
var viewModel = new UsrControlViewModel();
UIElement uiElement = ViewLocator.LocateForModel(viewModel, null, null);
ViewModelBinder.Bind(viewModel, uiElement, null);
await DialogHost.Show(uiElement);
}
Again, I do not know Caliburn.Micro very well so it is possible someone else has a better solution, but this one appears to work.
Thank you @Keboo and @jespersh for all your help, I am also thinking that its CM that is not doing its task and not populating the values, so I will follow your suggestions and will test it.
Again thank you... :)
Most helpful comment
@infirazor Thank you for the sample. First of all I am not very familiar with the inner workings of Caliburn.Micro (I tend to avoid it, but that is a different discussion).
First, the
DialogHostinternally displays its content in a Popup control. So the XAML that you put inside of the DialogContent is not actually part of the same visual tree (I suspect this is likely contibuting to the problems). So when you toggle theIsDialogOpenproperty, it is merely toggling theIsOpenproperty on that internal Popup control. Which does not leave a lot of opportunities for Caliburn.Micro to wire up all of its magic.After digging through the WindowManager.ShowPopup method I would suggest changing up the way you are interacting with the DialogHost, and use the static Show methods. Something like this:
C# public async Task OpenDialog() { var viewModel = new UsrControlViewModel(); UIElement uiElement = ViewLocator.LocateForModel(viewModel, null, null); ViewModelBinder.Bind(viewModel, uiElement, null); await DialogHost.Show(uiElement); }Again, I do not know Caliburn.Micro very well so it is possible someone else has a better solution, but this one appears to work.