我在我的选项卡控件中有两个选项卡项目,我想给滑动效果(动画),同时选择一个选项卡项目形式另一个。 让我知道是否有人有一些想法来实现这个动画。 在此先感谢。WPF Tabcontrol:对选项卡项目选择滑动效果
5
A
回答
1
http://social.msdn.microsoft.com/Forums/en-AU/wpf/thread/ed8801d8-51c4-4671-8b8c-86544c6d434d 这是有益的,evergreen..i已经使用了一段时间以前
这似乎是更新 http://blogs.intuidev.com/post/2010/01/26/TabControlStyling_PartTwo.aspx
多了不知道你所说的滑动效果是什么意思?版对我有什么例子来理解
0
XAML代码:
<Window x:Class="TabControlAnimation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" WindowState="Maximized">
<Grid HorizontalAlignment="Center" Name="maingrid">
<Grid.Resources>
<DataTemplate x:Key="TabTemplate">
<Grid Name="gd">
<ContentControl Content="{Binding}"></ContentControl>
</Grid>
</DataTemplate>
</Grid.Resources>
<StackPanel Orientation="Horizontal">
<TabControl ContentTemplate="{StaticResource TabTemplate}" Name="_menuTabControl" TabStripPlacement="Top" Width="auto" Height="{Binding ElementName=maingrid, Path=Height}" SelectionChanged="_menuTabControl_SelectionChanged">
<TabItem Header="MyTabItem1">
<Grid Background="Red">
<TextBlock Text="This is tab1"></TextBlock>
</Grid>
</TabItem>
<TabItem Header="MyTabItem2">
<Grid Background="Green">
<TextBlock Text="This is tab2"></TextBlock>
</Grid>
</TabItem>
<TabItem Header="MyTabItem3">
<Grid Background="Yellow">
<TextBlock Text="This is tab3"></TextBlock>
</Grid>
</TabItem>
<TabItem Header="MyTabItem4">
<Grid Background="Violet">
<TextBlock Text="This is tab4"></TextBlock>
</Grid>
</TabItem>
<TabItem Header="MyTabItem5">
<Grid Background="Blue">
<TextBlock Text="This is tab5"></TextBlock>
</Grid>
</TabItem>
</TabControl>
</StackPanel>
</Grid>
代码背后:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T:DependencyObject
{
if(depObj!=null)
{
for(int i=0;i<VisualTreeHelper.GetChildrenCount(depObj);i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
yield return (T)child;
foreach (T childOfChild in FindVisualChildren<T>(child))
yield return childOfChild;
}
}
}
int prev = -1, curr = -1;
private void _menuTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
curr = (sender as TabControl).SelectedIndex;
if(prev!=curr)
{
foreach(var rectangle in FindVisualChildren<Grid>(this))
{
if(rectangle.Name=="gd")
{
DoubleAnimation translate_x=null;
if(prev>curr)
{
translate_x = new DoubleAnimation()
{
From = -300,
To = 0,
Duration = TimeSpan.FromSeconds(0.3),
};
}
else
{
translate_x = new DoubleAnimation()
{
From = 300,
To = 0,
Duration = TimeSpan.FromSeconds(0.3),
};
}
var translate_y = new DoubleAnimation()
{
From = 0,
To = 0,
Duration = TimeSpan.FromSeconds(1),
};
TranslateTransform translateTransform1 = new TranslateTransform();
translateTransform1.BeginAnimation(TranslateTransform.XProperty, translate_x);
translateTransform1.BeginAnimation(TranslateTransform.YProperty, translate_y);
rectangle.RenderTransform = translateTransform1;
prev = curr;
}
}
}
}
}
相关问题
- 1. MVVM从TabControl中选择新选项卡
- 2. 滑动切换选项卡选择
- 3. WPF TabControl的重新排序选项卡
- 4. MVVM Tabcontrol更改选项卡
- 5. TabControl总是调整大小到选定的选项卡项目?
- 6. iOS的滑动效果ViewControllers - Instagram的活动选项卡
- 7. 滑动选项卡 - NullPointerException - Toolbar.getTitle()
- 8. 滑动选项卡主机
- 9. TabControl保存选定的选项卡项目已更改
- 10. 如何在选择选项卡项目内容时聚焦WPF选项卡项目?
- 11. 从TabItem到TabControl的TabControl中的WPF选项卡
- 12. jQuery选项卡和滑动效果 - 不一起工作
- 13. 为选项卡式内容添加不错的滑动效果
- 14. 如何在jQueryUI选项卡上实现滑动效果
- 15. 滑动选择MVVM中的GridView项目
- 16. WPF TabControl - 当TabItem可见性发生变化时选择不同的选项卡
- 17. 如果上述选项卡中选择
- 18. 在TabControl上选择新选项卡后,CollectionViewSource不能排序
- 19. 如何测试在VB.net中选择哪个选项卡TabControl
- 20. 滑动到图像基于URL哈希或选项卡选择
- 21. API 21滑动选项卡活动
- 22. jquery选项卡自动滑动
- 23. 如何更改滑动选项卡中选定的选项卡颜色?
- 24. 检测何时将选项卡项目添加到WPF选项卡控件
- 25. 动作条选项卡选择
- 26. 减速选项卡选择动画
- 27. 选择活动选项卡按日期
- 28. jQuery UI选项卡选择
- 29. 选择选项卡1.10.0
- 30. WPF - 选项卡控件中的两行选项卡 - 选项卡包装
其实,我想给滑动效果标签项的内容。比方说,tabitem包含一个stackpanel,tabitem 2包含一些其他控件,然后如果我选择了tab 2,那么tab 2的内容应该以滑动方式显示。 – prawin 2012-02-21 09:17:42
如果你在这里发布一些代码,那么我可以为你编辑.. – JackyBoi 2012-02-23 01:03:59