4

I have a ListBox

<ListBox Background="WhiteSmoke"
         Name="LstComponents"
         ItemsSource="{Binding}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding ComponentID}" />
                <TextBlock Text=" - " />
                <TextBlock Text="{Binding ComponentName}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

and a few buttons

<Button Content="Add New Components"
              Name="BtnAdd"
              Margin="5"
              Click="BtnAdd_Click" />
<Button Content="Update Components"
              Name="BtnUpdate"
              Grid.Column="1"
              Margin="5"
              Click="BtnUpdate_Click" />
<Button Content="Delete Components"
              Grid.Column="2"
              Name="BtnDelete"
              Margin="5"
              Click="BtnDelete_Click" />

Now I wanted the Update and Delete button to be disabled when it is loaded whereas it should enable if the list item in the ListBox is selected.

I don't want to write a code behind for it. Plz Suggest? How would i be able to accomplish this task in XAML

1 Answer 1

5

You can use

IsEnabled="{Binding ElementName=ListBoxName, Path=SelectedItems.Count}"

to make it work.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy