Note that there are some explanatory texts on larger screens.

plurals
  1. POBind listbox to ObservableCollection
    primarykey
    data
    text
    <p>I cannot find an answer I can work with for this problem. I have an ObservableCollection</p> <p>this is myClass: </p> <pre><code>public class myClass { public string name; public int[] dimensions = new int[2]; } </code></pre> <p>This is the code that sets ObservableCollection: </p> <pre><code>public class roomBuilder { private ObservableCollection&lt;myClass&gt; rooms; public roomBuilder() //constructor { string roomName; int[] dimensions = new int[2]; myClass newRoom = new myClass(); rooms = new ObservableCollection&lt;room&gt;(); roomName = "Hall"; dimensions[0] = 10; dimensions[1] = 12; newRoom.name = roomName; newRoom.dimensions = dimensions; rooms.Add(newRoom); roomListBox.DataContext = rooms; } </code></pre> <p>the XAML for this is: </p> <pre><code> &lt;ListBox Canvas.Left="-1" Canvas.Top="47" Height="419" Name="roomListBox" Width="481" BorderThickness="1" BorderBrush="GhostWhite" ItemsSource="{Binding}" DataContext="{Binding}"&gt; &lt;ListBox.ItemTemplate &gt; &lt;DataTemplate &gt; &lt;StackPanel Orientation="Vertical" Margin="1" Name="verstack" &gt; &lt;StackPanel Orientation="Horizontal" Margin="1" KeyDown="StackPanel_KeyDown" &gt; &lt;TextBox Text="{Binding Path=name}" IsReadOnly="False" FontFamily="Courier New" FontSize="22" Height="65" VerticalAlignment="Top" TextAlignment="Center"/&gt; &lt;TextBox Name="xDimension" Text="{Binding Mode=TwoWay, Path=dimensions[0] }" Width="70" Height="65" VerticalAlignment="Top" IsReadOnly="False" FontFamily="Courier New" Margin="2,0,1,0" FontSize="22" MaxLength="3" InputScope="TelephoneNumber" TextAlignment="Center" /&gt; &lt;TextBlock Name="separator" Text=":" FontSize="32" FontWeight="ExtraBold" Margin="1,4,1,0" /&gt; &lt;TextBox Name="yDimension" Text="{Binding Mode=TwoWay, Path=dimensions[1] }" Width="70" Height="65" VerticalAlignment="Top" IsReadOnly="False" FontFamily="Courier New" Margin="1,0,2,0" FontSize="22" MaxLength="3" InputScope="TelephoneNumber" TextAlignment="Center"/&gt; </code></pre> <p>I havent closed the Xaml off here , there's a load more underneath it, when I run this nothing is displayed and I just don't know what the problem is, I've been hammering away at it for 2 days, please someone help </p>
    singulars
    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