Note that there are some explanatory texts on larger screens.

plurals
  1. POcombobox binding in a listviewitem
    primarykey
    data
    text
    <p>I have a <code>ListView</code> declared like this : </p> <pre><code>&lt;ListView x:Name="lvRSU" Margin="3" Background="#84978F" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding rsus}"&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid Grid.Row="0" VerticalAlignment="Center"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="90"/&gt; &lt;ColumnDefinition Width="240"/&gt; &lt;ColumnDefinition Width="40"/&gt; &lt;ColumnDefinition Width="40"/&gt; &lt;ColumnDefinition Width="110"/&gt; &lt;ColumnDefinition Width="100"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Content="{Binding Name}" ContentStringFormat="{}{0} Path" VerticalAlignment="Center" /&gt; &lt;TextBox Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="2,0,0,0"/&gt; &lt;Button Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="22" Height="22" MaxHeight="22" MaxWidth="22" ToolTip="Open .rsu file" SnapsToDevicePixels="True"&gt; &lt;Image Source="Resources/Folder16.png" Stretch="Uniform" &gt;&lt;/Image&gt; &lt;/Button&gt; &lt;CheckBox Grid.Column="3" Content="En" VerticalAlignment="Center"/&gt; &lt;ComboBox ItemsSource="{Binding sensorTypes}" Grid.Column="4" HorizontalAlignment="Stretch" VerticalAlignment="Center"&gt; &lt;ComboBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding}"/&gt; &lt;/DataTemplate&gt; &lt;/ComboBox.ItemTemplate&gt; &lt;/ComboBox&gt; &lt;CheckBox Grid.Column="5" Content="{Binding Name}" ContentStringFormat="Inv {0}" VerticalAlignment="Center" Margin="2,1,1,1"/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; </code></pre> <p>and in the .cs file i have the following connection : </p> <pre><code>public ReadOnlyObservableCollection&lt;string&gt; _sensorTypes = new ReadOnlyObservableCollection&lt;string&gt;(new ObservableCollection&lt;string&gt;() { "1", "2"}); public ReadOnlyObservableCollection&lt;string&gt; sensorTypes { get { return _sensorTypes; } } </code></pre> <p>also i set the <code>DataContext</code> for my ListView : </p> <pre><code>lvRSU.DataContext = this; </code></pre> <p>But i can't get the items in my combobox at all. Maybe there is a problem because it's inside the grid ?</p> <p>It's ok i got it now.</p> <pre><code> ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ListView},Path=DataContext.sensorTypes}" </code></pre> <p>This one made the difference. I am going to the DataContext of the ListView which contains at some point my combobox, and i set the Path from there. Thanks.</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.
 

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