Note that there are some explanatory texts on larger screens.

plurals
  1. POUser Control Not Rendering When Used as a DataTemplate?
    primarykey
    data
    text
    <p>I have a usercontrol which I want to use as a DataTemplate in a Listbox.</p> <p>This works:</p> <pre><code>&lt;ListBox&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid x:Name="Grid" Height="100" Width="880" Background="LightGray"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="24"/&gt; &lt;RowDefinition Height="24"/&gt; &lt;RowDefinition Height="24"/&gt; &lt;RowDefinition Height="24"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="190" /&gt; &lt;ColumnDefinition Width="100" /&gt; &lt;ColumnDefinition Width="100" /&gt; &lt;ColumnDefinition Width="100" /&gt; &lt;ColumnDefinition Width="190" /&gt; &lt;ColumnDefinition Width="200" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Grid.Column="0" Grid.Row="0"&gt;Client&lt;/Label&gt; &lt;Label Grid.Column="0" Grid.Row="2"&gt;Contact&lt;/Label&gt; &lt;Label Grid.Column="1" Grid.Row="0"&gt;Date Presentation&lt;/Label&gt; &lt;Label Grid.Column="2" Grid.Row="0"&gt;Action&lt;/Label&gt; &lt;Label Grid.Column="3" Grid.Row="0"&gt;Date Interview&lt;/Label&gt; &lt;Label Grid.Column="3" Grid.Row="2"&gt;Time Interview&lt;/Label&gt; &lt;Label Grid.Column="4" Grid.Row="0"&gt;Remarks&lt;/Label&gt; &lt;Label Grid.Column="5" Margin="0,0,2,0"&gt;managed by&lt;/Label&gt; &lt;ComboBox Grid.Column="0" Grid.Row="1" Margin="2" Text="{Binding Path=Customer}"&gt; &lt;!--Template--&gt; &lt;/ComboBox&gt; &lt;TextBox Grid.Column="0" Grid.Row="3" Margin="2" Text="{Binding Path=Contact}"&gt;&lt;/TextBox&gt; &lt;TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding Path=PresentationDate}"&gt;&lt;/TextBox&gt; &lt;ComboBox Grid.Column="2" Grid.Row="1" Margin="2" Text="{Binding Path=Action}"&gt; &lt;!--Template--&gt; &lt;/ComboBox&gt; &lt;TextBox Grid.Column="3" Grid.Row="1" Margin="2" Text="{Binding Path=InterviewDate}"&gt;&lt;/TextBox&gt; &lt;TextBox Grid.Column="3" Grid.Row="3" Margin="2" Text="{Binding Path=InterviewTime}"&gt;&lt;/TextBox&gt; &lt;TextBox Grid.Column="4" Grid.Row="1" Grid.RowSpan="3" Margin="2" Text="{Binding Path=Remarks}"&gt;&lt;/TextBox&gt; &lt;StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="1" &gt; &lt;ComboBox Width="124" Text="{Binding Path=Manager}" Margin="2"&gt;&lt;/ComboBox&gt; &lt;Button Width="60" Height="20" Margin="4,0,0,0" &gt;Mail&lt;/Button&gt; &lt;/StackPanel&gt; &lt;CheckBox Grid.Column="5" Grid.Row="3" Margin="2,2,4,2"&gt;Rejection communicated&lt;/CheckBox&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>If I put the exact same code from between the <code>&lt;DataTemplate</code>> tags:</p> <pre><code>&lt;UserControl x:Class="CandiMan.View.CandidatePresentationControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cm="clr-namespace:CandiMan;assembly=CandiMan" xmlns:vw="clr-namespace:CandiMan.View;assembly=CandiMan" xmlns:vm="clr-namespace:CandiMan.ViewModel;assembly=CandiMan" Height="100" Width="880" BorderBrush="Black" BorderThickness="1"&gt; &lt;Grid x:Name="Grid" Height="100" Width="880" Background="LightGray"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="24"/&gt; &lt;RowDefinition Height="24"/&gt; &lt;RowDefinition Height="24"/&gt; &lt;RowDefinition Height="24"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="190" /&gt; &lt;ColumnDefinition Width="100" /&gt; &lt;ColumnDefinition Width="100" /&gt; &lt;ColumnDefinition Width="100" /&gt; &lt;ColumnDefinition Width="190" /&gt; &lt;ColumnDefinition Width="200" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Grid.Column="0" Grid.Row="0"&gt;Client&lt;/Label&gt; &lt;Label Grid.Column="0" Grid.Row="2"&gt;Contact&lt;/Label&gt; &lt;Label Grid.Column="1" Grid.Row="0"&gt;Date Presentation&lt;/Label&gt; &lt;Label Grid.Column="2" Grid.Row="0"&gt;Action&lt;/Label&gt; &lt;Label Grid.Column="3" Grid.Row="0"&gt;Date Interview&lt;/Label&gt; &lt;Label Grid.Column="3" Grid.Row="2"&gt;Time Interview&lt;/Label&gt; &lt;Label Grid.Column="4" Grid.Row="0"&gt;Remarks&lt;/Label&gt; &lt;Label Grid.Column="5" Margin="0,0,2,0"&gt;managed by&lt;/Label&gt; &lt;ComboBox Grid.Column="0" Grid.Row="1" Margin="2" Text="{Binding Path=Customer}"&gt; &lt;!--Template--&gt; &lt;/ComboBox&gt; &lt;TextBox Grid.Column="0" Grid.Row="3" Margin="2" Text="{Binding Path=Contact}"&gt;&lt;/TextBox&gt; &lt;TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding Path=PresentationDate}"&gt;&lt;/TextBox&gt; &lt;ComboBox Grid.Column="2" Grid.Row="1" Margin="2" Text="{Binding Path=Action}"&gt; &lt;!--Template--&gt; &lt;/ComboBox&gt; &lt;TextBox Grid.Column="3" Grid.Row="1" Margin="2" Text="{Binding Path=InterviewDate}"&gt;&lt;/TextBox&gt; &lt;TextBox Grid.Column="3" Grid.Row="3" Margin="2" Text="{Binding Path=InterviewTime}"&gt;&lt;/TextBox&gt; &lt;TextBox Grid.Column="4" Grid.Row="1" Grid.RowSpan="3" Margin="2" Text="{Binding Path=Remarks}"&gt;&lt;/TextBox&gt; &lt;StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="1" &gt; &lt;ComboBox Width="124" Text="{Binding Path=Manager}" Margin="2"&gt;&lt;/ComboBox&gt; &lt;Button Width="60" Height="20" Margin="4,0,0,0" &gt;Mail&lt;/Button&gt; &lt;/StackPanel&gt; &lt;CheckBox Grid.Column="5" Grid.Row="3" Margin="2,2,4,2"&gt;Rejection communicated&lt;/CheckBox&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>into a usercontrol named CandidatePresentationControl and do it like</p> <pre><code>&lt;ListBox&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;vw:CandidatePresentationControl/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>it does not get rendered. No errors, just an empty listbox. Can someone help me??</p> <p>Thank you!</p> <p>edit: I forgot something, dunno if it matters: The whole thing I'm doing this in, is a usercontrol, too.</p>
    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.
 

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