How to select tabs on Silverlight TabControl in the VS designer
In XAML (Silverlight), how do I edit anything but the first tab in the VS Designer? All I can see is the first tab, and I don't know how to set 开发者_StackOverflow社区which one is selected so that I can see the content of all tabs. Thanks!
I don't know if there is a way to do this. What you could do is set the SelectedIndex property on your TabControl to be the tab you want to visualize and then delete this property when you're done.
<controls:TabControl SelectedIndex="1">
<controls:TabItem Header="Hello">
<controls:TabItem.Content>
<StackPanel Width="400" Height="300">
<TextBlock Text="Content" />
<TextBlock Text="Content" />
<TextBlock Text="Content" />
<TextBlock Text="Content" />
</StackPanel>
</controls:TabItem.Content>
</controls:TabItem>
<controls:TabItem Header="Hello 2">
<controls:TabItem.Content>
<StackPanel Width="400"
Height="300">
<TextBlock Text="Content 2" />
<TextBlock Text="Content 2" />
<TextBlock Text="Content 2" />
<TextBlock Text="Content 2" />
</StackPanel>
</controls:TabItem.Content>
</controls:TabItem>
</controls:TabControl>
Another solution is to create the contents of each tab as a separate control.
- EditOrder.xaml
- EditOrder_CancelOrder.xaml
- EditOrder_EditItems.xaml
The DataContext is automatically inherited by child controls in Silverlight so you don't have to set the DataContext on each tab.
This makes your tab content modular and more reusable from the start. Of course it depends on the circumstances and what your app is doing, but its one way to avoid having to switch tabs by having to set IsSelected=true.
Note: don't get SelectedIndex on the TabControl confused with IsSelected on the TabItem.
Using IsSelected="true" doesn't work reliably to select a tab (in VS2010)
精彩评论