Herry Markowitz
Well-known member
- Joined
- Oct 22, 2015
- Messages
- 46
- Programming Experience
- 1-3
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 in order to prevent a TabItem from being selected.
https://joshsmithonwpf.wordpress.com...eing-selected/
Converted code via http://converter.telerik.com/;
My XAML codes;
Here is the error picture: https://prnt.sc/ijtvm4
To be honest I am not good at with constructors.
So I need you support.
https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
I have found following source in order to prevent a TabItem from being selected.
https://joshsmithonwpf.wordpress.com...eing-selected/
VB.NET:
[COLOR=#333333]public Window1()[/COLOR]{
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;
} [COLOR=#333333]}[/COLOR]
Converted code via http://converter.telerik.com/;
VB.NET:
[COLOR=#333333]Public Sub Window1()[/COLOR] 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 [COLOR=#333333]End Sub[/COLOR]
My XAML codes;
VB.NET:
[COLOR=#333333]<Window x:Class="MainWindow"[/COLOR] xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TabControlSample" Height="200" Width="250">
<Grid>
<TabControl x:Name="tab">
<TabItem Header="General">
<Label Content="Content goes here..." />
</TabItem>
<TabItem Header="Security" />
<TabItem Header="Details" />
</TabControl>
</Grid> [COLOR=#333333]</Window>[/COLOR]
Here is the error picture: https://prnt.sc/ijtvm4
To be honest I am not good at with constructors.
So I need you support.