January 22nd, 2010 02:44 PM
#1
Pre-setting the ComboBox selection in XAML
Colleagues,
I would like to pre-set the ComboBox in XAML. For example, there are 3 options: “4800”, “9600”, “19200”. I know that the text of the pre-selected item is “9600”. Which properties of ComboBox should I assign? Is it possible to do it entirely in XAML without writing code for looking up the index from the item text.
So far, I’ve tried this:
Code:
<ComboBox Name="cboBaudRate"
Grid.Column="1" Grid.Row="1" Margin="0,2,0,0" HorizontalAlignment="Left" Width="72" Height="20" VerticalAlignment="Top"
SelectedItem="9600" IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource SerialPortOptions}, XPath=./BaudRates/BaudRate }" />
But it keeps selecting the 1st option “4800”, probably because the index is initially set to 0.
Suggestions, insight, references are much appreciated.
- Nick
Last edited by kender_a; January 22nd, 2010 at 02:57 PM .
January 22nd, 2010 02:56 PM
#2
Re: Pre-setting the ComboBox selection in XAML
Resolved. Assigning SelectedValue instead of SelectedItem worked.
The working XAML looks like this:
Code:
<ComboBox Name="cboBaudRate"
Grid.Column="1" Grid.Row="1" Margin="0,2,0,0" HorizontalAlignment="Left" Width="72" Height="20" VerticalAlignment="Top"
SelectedValue="9600"
ItemsSource="{Binding Source={StaticResource SerialPortOptions}, XPath=./BaudRates/BaudRate }" />
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks