ListBox's behavior is that the first item is selected automatically, how can I avoid that??
Note: I want to do this with pure xaml, if you have any code-behind ideas then please don't bother yourself.
ListBox's behavior is that the first item is selected automatically, how can I avoid that??
Note: I want to do this with pure xaml, if you have any code-behind ideas then please don't bother yourself.
You could set SelectedIndex to -1 :
<ListBox ItemsSource="{Binding MyData}" SelectedIndex="-1"/>
Note: I want to do this with pure xaml, if you have any code-behind ideas then please don't bother yourself.
Unfortunately you can't do everything in XAML... you can usually avoid code-behind, but you still need to write converters, markup extensions or attached properties
Is SelectedIndex the property you're looking for ? Or maybe I don't get your point...
Well i tried this using FocusManager.FocusedElement .. and made the intial focus to
listbox itself.. so it has the focus..but no element is selected..
if u press down or tab ..the 1st element of the listbox will be selected...
<Window
......
FocusManager.FocusedElement="{Binding ElementName=listbox2}">
<ListBox x:Name="listbox2" HorizontalAlignment="Left"
VerticalAlignment="Bottom" Width="117.333" Height="116"
Margin="30.667,0,0,30">
<ListBoxItem>Jim</ListBoxItem>
<ListBoxItem>Mark</ListBoxItem>
<ListBoxItem>Mandy</ListBoxItem>
</ListBox>
Same issue here. Anyone found a "clean" solution?
The problem is the same here, it causes a bunch of triggers to execute.
Obvious solution/fix:
1) Remove SelectionChanged event handlers from XAML
2) Add handlers in constructor after InitializeComponents has loaded the listbox.