Greetings, Is there any way to create something like automatic combobox switcher in WPF? The case is that I want to add some links to combobox and these links should automatically changed after, let's say 10sek. Something like dynamic advertisements or combobox links rotator. Is there any way to achieve something like that ?
EDIT: To be more specific: combobox should cont开发者_运维百科ain links, for instance:
- Link1
- Link2
- Link3
by default, Link1 will be chosen but after 10seconds, Link2 will be chosen, then after next 10 seconds Link3 will be chosen. Then again, after next 10 seconds, Link1 will be chosen
Are you sure you want to use a combobox for this? What if the user selected a specific link? Will it be changed within 10 seconds to another link?
Anyway, why not just add a timer to your code behind and every 10 seconds set SelectedIndex to next item.
XAML:
<ComboBox Loaded="OnComboBoxLoaded" SelectedIndex="0">
<Hyperlink>link 1</Hyperlink>
<Hyperlink>link 2</Hyperlink>
<Hyperlink>link 3</Hyperlink>
</ComboBox>
Code behind:
private void OnComboBoxLoaded(object sender, RoutedEventArgs e)
{
ComboBox comboBox = sender as ComboBox;
new DispatcherTimer(new TimeSpan(0, 0, 10),
DispatcherPriority.Normal,
(sender2, e2) => comboBox.SelectedIndex = (comboBox.SelectedIndex + 1)%comboBox.Items.Count,
Dispatcher);
}}
精彩评论