Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding IsEnabled to count of selected items
Message
From
06/01/2014 07:51:59
 
 
To
06/01/2014 07:12:15
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01591392
Message ID:
01591393
Views:
40
>Hi,
>
>I have a delete button on a WPF form which I only want enabled whenever one and only one item is selected in a grid on the same form. I figure I have to do something like this:
>
>IsEnabled="{Binding ElementName=grdManifest, Path=Items.Selected.Count = 1}"
>
>but that isn't accepted as valid code.
>
>Any ideas on how to do this?

I think you will need to add a property to your viewmodel. Something like:
public bool EnableButton
        {
            get { return grdManifest.SelectedItems.Count == 1; }
        }
then bind:
IsEnabled="{Binding Path=EnableButton}"
(untested :-{)

UPDATE: You probably need to trigger a PropertyChanged on the EnableButton:
void grdManifest_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            PropertyChanged(this,new PropertyChangedEventArgs("EnableButton"));
        }
Previous
Reply
Map
View

Click here to load this message in the networking platform