Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

[RESOLVED] How to prevent a TabItem from being selected

$
0
0
There is no TabControl.Selecting Event in the WPF while there is in the Winform as you can see following.
https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx


I have found following source for this issue.
https://joshsmithonwpf.wordpress.com...eing-selected/

Code:

public Window1()
{
    InitializeComponent();

    base.DataContext = new DataSource();

    var items = new string[] { "A", "B", "C" };
    this.tab.ItemsSource = items;
    var collView = CollectionViewSource.GetDefaultView(items);
    collView.CurrentChanging += this.OnTabItemSelecting;
}

void OnTabItemSelecting(object sender, CurrentChangingEventArgs e)
{
    bool allow = this.chk.IsChecked.GetValueOrDefault();
    if (!allow)
    {
          // SelectedContent hasn't changed yet, so use it to figure out
          // the index of the previously selected tab
          int prevIdx = this.tab.Items.IndexOf(this.tab.SelectedContent);
          this.tab.SelectedIndex = prevIdx;
    }
}


Converted code via http://converter.telerik.com/;

Code:

Public Sub Window1()
    InitializeComponent()
    MyBase.DataContext = New DataSource()
    Dim items = New String() {"A", "B", "C"}
    Me.tab.ItemsSource = items
    Dim collView = CollectionViewSource.GetDefaultView(items)
    collView.CurrentChanging += AddressOf Me.OnTabItemSelecting
End Sub

Private Sub OnTabItemSelecting(ByVal sender As Object, ByVal e As CurrentChangingEventArgs)
    Dim allow As Boolean = Me.chk.IsChecked.GetValueOrDefault()
    If Not allow Then
        Dim prevIdx As Integer = Me.tab.Items.IndexOf(Me.tab.SelectedContent)
        Me.tab.SelectedIndex = prevIdx
    End If
End Sub

But I have no idea how that vb.net code works.

So, please somebody explain me how that vb.net code works in WPF.

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>