<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to get selected ListBoxItem(s)? in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153286#M7922</link>
    <description>&lt;P&gt;I publish a list of objects in a ListBox and hoped to bind the selection of an item to a boolean property.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;ListBox x:Name="DataLayerList" SelectionMode="Extended"    IsTextSearchEnabled="True" ItemsSource="{Binding LayersFiltered, Mode=OneWay}"&amp;gt;
    &amp;lt;ListBox.ItemContainerStyle&amp;gt;
        &amp;lt;Style TargetType="{x:Type ListBoxItem}"&amp;gt;
            &amp;lt;Setter Property="IsSelected" Value="{Binding ListItemSelected, Mode=TwoWay}"/&amp;gt;
        &amp;lt;/Style&amp;gt;
    &amp;lt;/ListBox.ItemContainerStyle&amp;gt;
&amp;lt;/ListBox&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LayersFiltered&lt;/EM&gt; is a list of &lt;EM&gt;ThemeLayer&lt;/EM&gt;, where Theme layer is defined as such.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class ThemeLayer
    {
        public readonly string Name;
        public readonly string Id;
        public readonly string Type;
        
        public override string ToString()
        {
            return Name;
        }

        public ThemeLayer(string name, string id, string type)
        {
            Name = name;
            Id = id;
            Type = type;
        }

        public bool IsSelected { get; set; }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within my ViewModel &lt;EM&gt;LayersFiltered&lt;/EM&gt; and &lt;EM&gt;ListItemSelected&lt;/EM&gt; are defined as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private List&amp;lt;ThemeLayer&amp;gt; _layersFiltered;
public List&amp;lt;ThemeLayer&amp;gt; LayersFiltered
    {
        get =&amp;gt; _layersFiltered;
        set =&amp;gt; SetProperty(ref _layersFiltered, value, () =&amp;gt; LayersFiltered);
    }

private bool _listItemSelected;
public bool ListItemSelected
    {
        get =&amp;gt; _listItemSelected;
        set 
        {
            SetProperty(ref _listItemSelected, value, () =&amp;gt; ListItemSelected);
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, &lt;EM&gt;ListItemSelected&lt;/EM&gt; is never triggered when I select a ListBoxItem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had a look at &lt;A href="https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/44183d0d5a9bc5da6fb8b9229211cc707dd2b874/Framework/RemoveAddins/SampleBackstageTabView.xaml" target="_blank" rel="noopener"&gt;https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/44183d0d5a9bc5da6fb8b9229211cc707dd2b874/Framework/RemoveAddins/SampleBackstageTabView.xaml&lt;/A&gt; but fail to transfer it into my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Mar 2022 09:54:28 GMT</pubDate>
    <dc:creator>TomGeo</dc:creator>
    <dc:date>2022-03-14T09:54:28Z</dc:date>
    <item>
      <title>How to get selected ListBoxItem(s)?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153286#M7922</link>
      <description>&lt;P&gt;I publish a list of objects in a ListBox and hoped to bind the selection of an item to a boolean property.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;ListBox x:Name="DataLayerList" SelectionMode="Extended"    IsTextSearchEnabled="True" ItemsSource="{Binding LayersFiltered, Mode=OneWay}"&amp;gt;
    &amp;lt;ListBox.ItemContainerStyle&amp;gt;
        &amp;lt;Style TargetType="{x:Type ListBoxItem}"&amp;gt;
            &amp;lt;Setter Property="IsSelected" Value="{Binding ListItemSelected, Mode=TwoWay}"/&amp;gt;
        &amp;lt;/Style&amp;gt;
    &amp;lt;/ListBox.ItemContainerStyle&amp;gt;
&amp;lt;/ListBox&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LayersFiltered&lt;/EM&gt; is a list of &lt;EM&gt;ThemeLayer&lt;/EM&gt;, where Theme layer is defined as such.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class ThemeLayer
    {
        public readonly string Name;
        public readonly string Id;
        public readonly string Type;
        
        public override string ToString()
        {
            return Name;
        }

        public ThemeLayer(string name, string id, string type)
        {
            Name = name;
            Id = id;
            Type = type;
        }

        public bool IsSelected { get; set; }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within my ViewModel &lt;EM&gt;LayersFiltered&lt;/EM&gt; and &lt;EM&gt;ListItemSelected&lt;/EM&gt; are defined as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private List&amp;lt;ThemeLayer&amp;gt; _layersFiltered;
public List&amp;lt;ThemeLayer&amp;gt; LayersFiltered
    {
        get =&amp;gt; _layersFiltered;
        set =&amp;gt; SetProperty(ref _layersFiltered, value, () =&amp;gt; LayersFiltered);
    }

private bool _listItemSelected;
public bool ListItemSelected
    {
        get =&amp;gt; _listItemSelected;
        set 
        {
            SetProperty(ref _listItemSelected, value, () =&amp;gt; ListItemSelected);
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, &lt;EM&gt;ListItemSelected&lt;/EM&gt; is never triggered when I select a ListBoxItem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had a look at &lt;A href="https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/44183d0d5a9bc5da6fb8b9229211cc707dd2b874/Framework/RemoveAddins/SampleBackstageTabView.xaml" target="_blank" rel="noopener"&gt;https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/44183d0d5a9bc5da6fb8b9229211cc707dd2b874/Framework/RemoveAddins/SampleBackstageTabView.xaml&lt;/A&gt; but fail to transfer it into my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 09:54:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153286#M7922</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2022-03-14T09:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected ListBoxItem(s)?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153311#M7925</link>
      <description>&lt;P&gt;Thanks, but I am not interested in a Taco Bell survey &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; Chance you pasted the wrong link in?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 12:33:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153311#M7925</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2022-03-14T12:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected ListBoxItem(s)?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153327#M7928</link>
      <description>&lt;P&gt;I removed it to Spam&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 13:33:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153327#M7928</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-14T13:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected ListBoxItem(s)?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153361#M7930</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the problem is with one way binding of LayersFiltered.&lt;/P&gt;&lt;P&gt;Try to set two ways as in sample:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ItemsSource="{Binding LayersFiltered, Mode=TwoWay}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 14:29:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153361#M7930</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2022-03-14T14:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected ListBoxItem(s)?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153369#M7933</link>
      <description>&lt;P&gt;I tried TwoWay before and it did not change the behaviour... Would be still interested in a solution for TwoWay binding. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I solved it now with OneWay binding. In need of a button to react on the users selection I implemented the button by referencing the ListBox and its SelectedItems property.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;Button Content="Add selected data" Grid.Row="3"
                VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,5"
                Style="{DynamicResource Esri_Button}" Command="{Binding AddServiceCommand}" 
                CommandParameter="{Binding ElementName=DataLayerList, Path=SelectedItems}"/&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That works without any problem and the custom command to execute the buttons functionality receives a collection of objects of type ThemeLayer.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 14:56:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153369#M7933</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2022-03-14T14:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected ListBoxItem(s)?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153372#M7935</link>
      <description>&lt;P&gt;Two way binding is in&amp;nbsp;RemoveAddins sample&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;            &amp;lt;ListBox Height="185"
                ScrollViewer.VerticalScrollBarVisibility="Auto"                
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"                  
                ItemsSource="{Binding AddIns, Mode=TwoWay}"
                ItemTemplate="{StaticResource AddInItem}"
                SelectionMode="Multiple"&amp;gt;
                &amp;lt;ListBox.ItemContainerStyle&amp;gt;
                    &amp;lt;!-- This Style binds a ListBoxItem to a the ViewModelItem. --&amp;gt;
                    &amp;lt;Style TargetType="ListBoxItem"&amp;gt;
                        &amp;lt;Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /&amp;gt;
                    &amp;lt;/Style&amp;gt;
                &amp;lt;/ListBox.ItemContainerStyle&amp;gt;
            &amp;lt;/ListBox&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try to check all other settings of listbox. One of them could be&amp;nbsp;&lt;SPAN class=""&gt;ItemTemplate&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;{StaticResource AddInItem}&lt;SPAN class=""&gt;". They use template for listbox item. You can do the same.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 15:11:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153372#M7935</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2022-03-14T15:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get selected ListBoxItem(s)?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153381#M7936</link>
      <description>&lt;P&gt;I tried several times to get this part with the ItemTemplate and the namespace right, and failed every time. What usually happened was that the project ran, but my ListBox was not showing any content anymore.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 15:16:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-get-selected-listboxitem-s/m-p/1153381#M7936</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2022-03-14T15:16:19Z</dc:date>
    </item>
  </channel>
</rss>

