Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
370
Bind CloseButtonVisibility to ViewModel
posted

Hy Supportteam,

i've the following problem.
I want to bind the Property "CloseButtonVisibility" to my ViewModel.
I've played arroung with serveral things, but nothing helps.
Here is my samplecode.

 

 

 

 

 

 

 

 

 

 

 

 

 

<igWindows:XamTabControl Theme="[Current]" ItemsSource="{Binding Path=LoadedViewModels}" IsSynchronizedWithCurrentItem="True"
igWindows:TabItemEx.Closed="OnTabItemExClosed" >
<igWindows:XamTabControl.Resources>
<Style TargetType="igWindows:TabItemEx">
<Setter Property="HeaderTemplate" Value="{StaticResource headerText}" />
</Style>
</igWindows:XamTabControl.Resources>
</igWindows:XamTabControl>

The Itemssource "LoadedViewModels" is a collecetion of my viewmodels and each has a bool prop for viewmodelcanclose.

Can you help my?

  • 30945
    Offline posted

    Hello,

     

    I am glad to hear that you manage to solve the issue that you are having. If you have any further questions on the matter please do not hesitate to ask.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

  • 54937
    Offline posted

    CloseButtonVisibility is an enumeration with values of Visible, WhenSelected, WhenSelectedOrHotTracked or Hidden. If you want to bind that to a boolean property then you will need to create your own IValueConverter to convert from boolean to whichevery one of those values you want to use. Alternatively you could bind the AllowClosing property of the TabItem to your ViewModelCanClose property and set the TabItemCloseButtonVisibility of the xamTabControl to Visible or one of the other non-hidden options. I've attached a basic sample doing this.

    TestProject.zip
  • 30945
    Suggested Answer
    Offline posted

    Hello, I am attaching a sample application that shows how you can bind the CloseButtonVisibility to a property of the view model object. The sample application uses the following style for the TabItemEx:

    <Style TargetType="igWindows:TabItemEx">
        <Setter Property="Header" Value="{Binding HeaderText}" /> 
        <Setter Property="CloseButtonVisibility" Value="{Binding CanClose,Converter={StaticResource BoolToVisibility}}"/>
    </Style>
    

    Which bind the header of the TabItemEx to property called HeaderText and the CloseButtonVisibility to CanClose property of the view model with the following converter:

        public class BoolToVisibilityconverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value != null)
                {
                    if ((bool)value)
                    {
                        return TabItemCloseButtonVisibility.Visible;
                    }
                    else
                    {
                        return TabItemCloseButtonVisibility.Hidden;
                    }
                }
                return value;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
    

    Converting the bool value to TabItemExCloseButtonVisibility.

     If you require any further clarifications please do not hesitate to ask.

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

     

    TabCtrlBindCloseButtonVisibility.zip