0

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 });    
        }
    }
}
Pedro Rodrigues
  • 1,662
  • 15
  • 19
  • Inside `DataGrid` add `ItemsSource="{Binding SuggestedCars}"` – sharp Dec 04 '17 at 08:05
  • @arcticwhite Nope. I'm using caliburn.micro whitch is automatically binding control to VM by x:name – Bornegio Dec 05 '17 at 09:49
  • You first need to check does caliburn.micro has a convention for Popup control, if not, you need to write it, or to bind using ItemsSource. – sharp Dec 05 '17 at 09:51

0 Answers0