How to create Animated TabControl in XAML in WPF?

MERUN KUMAR MAITY 511 Reputation points
2022-04-06T20:53:02.883+00:00

190713-ezgifcom-gif-maker.gif

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,377 questions
{count} votes

Accepted answer
  1. Hui Liu-MSFT 41,331 Reputation points Microsoft Vendor
    2022-04-13T07:05:20.653+00:00

    MainWindow.xaml:

    <Grid  DataContext="{StaticResource vm}" >  
            <Grid.RowDefinitions>  
                <RowDefinition Height="*"/>  
                <RowDefinition Height="50"/>  
            </Grid.RowDefinitions>  
            <TabControl     SelectedIndex="{Binding Selected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"     Grid.Row="0"   x:Name="TestTabs">  
                <TabItem Name="Tab1" Header="News" />  
                <TabItem Name="Tab2" Header="DLC" />  
                <TabItem Name="Tab3" Header="Settings"/>  
            </TabControl>  
            <DockPanel  x:Name="rp" Grid.Row="0" LastChildFill="False" HorizontalAlignment="Stretch">  
                <Canvas DockPanel.Dock="Left" >  
                    <Rectangle x:Name="Rect1" Fill="#ff0000" VerticalAlignment="Top"  Height="4" Margin="0,25,0,0"   
                               SnapsToDevicePixels="True" UseLayoutRounding="True" RenderOptions.EdgeMode="Aliased"   
                               Width="{Binding ElementName=TestTabs, Path=SelectedItem.ActualWidth}"  RenderOptions.BitmapScalingMode="HighQuality" />  
                </Canvas>  
            </DockPanel>  
            <StackPanel Orientation="Horizontal" Grid.Row="1">  
                <Label Content="selected" Width="100" Height="40" />  
                <TextBox x:Name="sele" Text="{Binding Selected}" Width="100" Height="40" Background="AliceBlue" Margin="5"/>  
                <Label Content="previousSelected"  Width="100" Height="40"/>  
                <TextBox x:Name="prev" Text="{Binding PreviousSelected,Mode=OneWay}" Width="100" Height="40" Background="AliceBlue" Margin="5"/>  
            </StackPanel>  
        </Grid>  
    

    MainWindow.xaml.cs:

    using System.ComponentModel;  
    using System.Windows;  
    namespace TabControlBindSlide  
    {  
      public partial class MainWindow : Window  
      {  
        public MainWindow()  
        {  
          InitializeComponent();  
        }  
      }  
      class TestViewModel : INotifyPropertyChanged  
      {  
        private int _selected;  
        public int Selected  
        {  
          get { return _selected; }  
          set  
          {  
            int temp = _selected;  
            _selected = value;  
            _previousSelected = temp;  
            NotifyPropertyChanged("Selected", temp, value);  
            NotifyPropertyChanged("PreviousSelected", temp, temp);  
          }  
        }  
        int _previousSelected = 0;  
        public int PreviousSelected  
        {  
          get { return _previousSelected; }  
        }  
        public event PropertyChangedEventHandler PropertyChanged;  
        protected void NotifyPropertyChanged<T>(string propertyName, T oldvalue, T newvalue)  
        {  
          OnPropertyChanged(this, new PropertyChangedExtendedEventArgs<T>(propertyName, oldvalue, newvalue));  
        }  
        public virtual void OnPropertyChanged(object sender, PropertyChangedEventArgs e)  
        {  
          PropertyChangedEventHandler handler = PropertyChanged;  
          if (handler != null)  
            handler(sender, e);  
        }  
      }  
      public class PropertyChangedExtendedEventArgs<T> : PropertyChangedEventArgs  
      {  
        public virtual T OldValue { get; private set; }  
        public virtual T NewValue { get; private set; }  
      
        public PropertyChangedExtendedEventArgs(string propertyName, T oldValue, T newValue)  
            : base(propertyName)  
        {  
          OldValue = oldValue;  
          NewValue = newValue;  
        }  
      }  
    }  
    

    MainWindow.xaml:(include resource) :
    192830-btxt.txt


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful