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?

Parents
No Data
Reply
  • 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
Children