Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9128669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:34:11+00:00 2026-06-17T07:34:11+00:00

I have following code. Here listClear is an object, which is filled by ViewModel.

  • 0

I have following code. Here listClear is an object, which is filled by ViewModel. I am using properties of this object to fill a Grid. In below code what property should I use to make Button disable in DataTrigger. I want Button to be disabled when Grid is empty, otherwise it should be enabled.

<Button Grid.Column="3" Margin="2" Command="{Binding Path=ClearCommand}" Content="Clear">
    <Button.Style>
        <Style TargetType="Button">
            <Setter Property="IsEnabled" Value="True" />

                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=listClear}" Value="">
                        <Setter Property="IsEnabled" Value="False"/>
                    </DataTrigger>
                </Style.Triggers>
        </Style>
    </Button.Style>
</Button>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:34:12+00:00Added an answer on June 17, 2026 at 7:34 am

    You can use the List Count property for this to indicate empty

    Example:

    public partial class MainWindow : Window 
    {
        private ObservableCollection<string> myVar = new ObservableCollection<string>();
    
        public MainWindow()
        {
            InitializeComponent();
            MyList.Add("test");
        }
    
        public ObservableCollection<string> MyList
        {
            get { return myVar; }
            set { myVar = value; }
        }
    
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MyList.Clear();
        }
    
    }
    

    Xaml:

    <Window x:Class="WpfApplication11.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:WpfApplication11"
            Title="MainWindow" Height="136.3" Width="208" x:Name="UI">
        <Grid DataContext="{Binding ElementName=UI}">
            <Button Content="Clear" Click="Button_Click">
                <Button.Style>
                    <Style TargetType="Button">
                        <Setter Property="IsEnabled" Value="True" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=MyList.Count}" Value="0">
                                <Setter Property="IsEnabled" Value="False"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </Grid>
    </Window>
    

    If your only using IEnumerable<T> its a bit more difficult because IEnumerable has no public properties to bint to, you would have to make a converter.

    Something like this

    public class IsEmptyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is IEnumerable)
            {
                var enumerable = (IEnumerable)value;
                foreach (var item in enumerable)
                {
                    return false;
                }
            }
            return true;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Xaml:

    <Window x:Class="WpfApplication11.MainWindow"
            xmlns:local="clr-namespace:Namespace for converter"
    ....
    ....
     <Window.Resources>
            <local:IsEmptyConverter x:Key="IsEmptyConverter" />
     </Window.Resources>
    ....
    ....
       <DataTrigger Binding="{Binding Path=MyList, Converter={StaticResource IsEmptyConverter}}" Value="true">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this following code, here CssClass is of the String type. <asp:Panel ID=Panel1
I have the following code, which compiles but doesn't bring back any data. Here
I have this following jquery text fly-in animation.Here is my code before I explain
I have the following code which looks like this: <div id=container> // 3 lines
I have the following code: $data['x'] = $this->x->getResults(); $data['y'] = $data['x']; //some code here
I have the following code here that won't run on ARC since it combines
I have following code: public static void ProcessStep(Action action) { //do something here if
I have the following code. Here I am matching the vowels characters words :
Right, starting to go crazy here. I have the following code: var query =
Have a look here: In the following code, what would be the type of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.