locked
IsSelected property of ComboBoxItem not saving RRS feed

  • Question

  • When I make a ComboBox with a ComboBoxItem beneath it (indented) in the Objects and Timeline panel, the IsSelected property is somehow erased when I save.

    I can select the ComboBox, then select the ComboBoxItem, then check IsSelected in the Common Properties - but this setting simply will not persist after I have Published to SharePoint.

    Why is this happening and how can I make the IsSelected property persist?


    "We're all in it together, kid." - Harry Tuttle, Heating Engineer

    Wednesday, November 28, 2012 9:31 PM

Answers

  • After looking at the msdn docs, I don't think setting IsSelected does what you want. Reading the value can tell you if it is selected, but I think the proper way to do this is to set SelectedIndex on the ComboBox.

    http://msdn.microsoft.com/en-us/library/system.windows.controls.listboxitem.isselected(v=vs.95).aspx

    http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectedindex(v=vs.95).aspx

    In your case, the xaml would look like this:

    <StackPanel Orientation="Horizontal">
    					<TextBlock Style="{StaticResource BasicTextBlock-Sketch}" TextWrapping="Wrap" Text="State:" Margin="60,0,0,0"/>
    					<ComboBox Style="{StaticResource ComboBox-Sketch}" Margin="5,0,15,0" SelectedIndex="0">
    						<ComboBoxItem Content="Please select" Style="{StaticResource ComboBoxItem-Sketch}"/>
    					</ComboBox>
    				</StackPanel>

    • Marked as answer by Bleak Morn Friday, November 30, 2012 7:49 PM
    Thursday, November 29, 2012 3:35 PM
    Moderator

All replies

  • Could you post the xaml that is generated? I tried this and it seems to work correctly for me. 

    You might also try "SelectedIndex" on the ComboBox, I think that is the proper way to set the selected item.

    Thursday, November 29, 2012 3:16 PM
    Moderator
  • <StackPanel Orientation="Horizontal">
    					<TextBlock Style="{StaticResource BasicTextBlock-Sketch}" TextWrapping="Wrap" Text="State:" Margin="60,0,0,0"/>
    					<ComboBox Style="{StaticResource ComboBox-Sketch}" Margin="5,0,15,0">
    						<ComboBoxItem Content="Please select" Style="{StaticResource ComboBoxItem-Sketch}" IsSelected="True"/>
    					</ComboBox>
    				</StackPanel>

    Looks fine in XAML - just not displaying properly in the UI. All I see is the ComboBox down arrow.

    "We're all in it together, kid." - Harry Tuttle, Heating Engineer

    Thursday, November 29, 2012 3:30 PM
  • After looking at the msdn docs, I don't think setting IsSelected does what you want. Reading the value can tell you if it is selected, but I think the proper way to do this is to set SelectedIndex on the ComboBox.

    http://msdn.microsoft.com/en-us/library/system.windows.controls.listboxitem.isselected(v=vs.95).aspx

    http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectedindex(v=vs.95).aspx

    In your case, the xaml would look like this:

    <StackPanel Orientation="Horizontal">
    					<TextBlock Style="{StaticResource BasicTextBlock-Sketch}" TextWrapping="Wrap" Text="State:" Margin="60,0,0,0"/>
    					<ComboBox Style="{StaticResource ComboBox-Sketch}" Margin="5,0,15,0" SelectedIndex="0">
    						<ComboBoxItem Content="Please select" Style="{StaticResource ComboBoxItem-Sketch}"/>
    					</ComboBox>
    				</StackPanel>

    • Marked as answer by Bleak Morn Friday, November 30, 2012 7:49 PM
    Thursday, November 29, 2012 3:35 PM
    Moderator
  • Thanks. Makes more sense than what I was trying to do. :)

    "We're all in it together, kid." - Harry Tuttle, Heating Engineer

    Friday, November 30, 2012 7:49 PM