Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding ObservableCollection to child window, design mode works, real data does not
    primarykey
    data
    text
    <p>I have the following code where the design mode works, but as soon I run it with real equal data the window just Shows the Default class Name <strong>DocumentViewer.ViewModel.ItemSelectorViewModel</strong> and nothing else (not unlike in design mode). I simply can't see the Problem.</p> <h2>ViewModel</h2> <pre><code>public class ItemSelectorViewModel : ViewModelBase { private ObservableCollection&lt;Document&gt; _pictureSelectors; public ItemSelectorViewModel() { if (Designer.IsInDesignMode()) { string xml = System.IO.File.ReadAllText(GlobalConstants.DesignTimeDataFile); IList&lt;Document&gt; list = ObjectSerializer.Deserialize&lt;List&lt;Document&gt;&gt;(xml); PictureSelector = list.ToObservableCollection(); } } public ObservableCollection&lt;Document&gt; PictureSelector { get { return _pictureSelectors; } set { if (_pictureSelectors == value) { return; } _pictureSelectors = value; RaisePropertyChanged("PictureSelector"); } } } </code></pre> <h2>View</h2> <pre><code>public partial class ItemSelectorView { public ItemSelectorView(ItemSelectorViewModel itemSelectorViewModel) { InitializeComponent(); if (!Designer.IsInDesignMode()) { Content = itemSelectorViewModel; } } } </code></pre> <h2>XAML</h2> <pre><code>&lt;Window x:Class="DocumentViewer.View.ItemSelectorView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModel="clr-namespace:DocumentViewer.ViewModel" Title="ItemSelector" Width="300" Height="321" WindowStyle="SingleBorderWindow" d:DataContext="{d:DesignInstance Type=viewModel:ItemSelectorViewModel, IsDesignTimeCreatable=True}" mc:Ignorable="d"&gt; &lt;Window.Resources /&gt; &lt;Grid x:Name="MyLayoutRoot" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="20*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;DataGrid x:Name="MyDataGrid" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AutoGenerateColumns="False" CanUserAddRows="False" ItemsSource="{Binding Path=PictureSelector}" SelectedCellsChanged="Item_SelectionChanged" SelectedValuePath="DocId" SelectionUnit="FullRow"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Binding="{Binding DocNumber}" Header="Tagesnummer" /&gt; &lt;DataGridTextColumn Binding="{Binding GraphicType}" Header="Grafiktyp" /&gt; &lt;DataGridTextColumn Binding="{Binding DocId}" Header="Doc ID" /&gt; &lt;/DataGrid.Columns&gt; &lt;DataGrid.ColumnHeaderStyle&gt; &lt;Style TargetType="{x:Type DataGridColumnHeader}"&gt; &lt;Setter Property="FontWeight" Value="Bold" /&gt; &lt;/Style&gt; &lt;/DataGrid.ColumnHeaderStyle&gt; &lt;/DataGrid&gt; &lt;/Grid&gt; </code></pre> <p></p> <h2>And I call the child from the parent with a RelayCommand</h2> <pre><code>ItemSelectorViewModel viewModel = new ItemSelectorViewModel(); viewModel.PictureSelector = _dataModel.DokumenteItems; ItemSelectorView view = new ItemSelectorView(viewModel); view.Owner = Application.Current.MainWindow; view.Show(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload