I am trying to insert a datagrid into popup, but it is't not working correctly (popup contains empty datagrid). I've tried to put my datagrid outside popup and it's worked. I guess popup behaves like seperate window, so I wonder if I supposed to create another ViewModel class for my popup, or is there another way to solve that?
My View xaml code:
<UserControl x:Class="MyApplication.Views.AddArrivalView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-MyApplication.Views" >
<Grid>
<StackPanel Orientation="Horizontal" Margin="5">
//<Some textblocks>
</StackPanel>
<Popup Width="700" Height="300" IsOpen="true">
<DataGrid x:Name="SuggestedCars"
AutoGenerateColumns="true"
IsReadOnly="True">
</DataGrid>
</Popup>
</Grid>
</UserControl>
My ViewModel
namespace MyApplication.ViewModels
{
class AddArrivalViewModel : PropertyChangedBase
{
private BindableCollection<Cars> _suggestedCars;
public BindableCollection<Cars> SuggestedCars
{
get
{
return _suggestedCars;
}
set
{
_suggestedCars = value;
NotifyOfPropertyChange("SuggestedCars");
}
}
public AddArrivalViewModel()
{
SuggestedCars = new BindableCollection<Cars>();
//add some test cars to collection
SuggestedCars.Add(new Cars() { Brand = "Opel", Model = "Corsa", Registration = "000000", ID = 0 });
}
}
}