Enable a button on a selected item

A few days ago I wrote a post about how to use the generic property setter in order to set IsEnabled on a button. I got the question how to do it in 9.1.2. Unfortunately the M3List does not expose the CurrentItem property in 9.1.2 so for M3Lists I have no solution. But for lists using the M3 APIS (MIListPanel) and the DataListPanel you have the option of checking the SelectedValue of the list and use a converter that will change a not null value to true.

My example has a list of Countries and a button that will be disabled unless a row in the list is selected.

Here is the xaml:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:util="clr-namespace:Mango.UI.Utils;assembly=Mango.UI" xmlns:mashup="clr-namespace:Mango.UI.Services.Mashup;assembly=Mango.UI" xmlns:m3="clr-namespace:MForms.Mashup;assembly=MForms">
   <util:IsNotNullOrEmptyConverter x:Key="notNullConverter" />
   <!-- the inversion of the first converter-->
   <util:IsNullOrEmptyConverter x:Key="isNullConverter" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="1*" />
    <ColumnDefinition Width="1*" />
  <m3:MIListPanel Name="CountryList" Margin="8">
    <m3:MIDataSource Program="CRS045MI" Transaction="LstCountry" InputFields="" />

       <mashup:Event SourceEventName="Startup">

  <ListView Name="listViewCountries" HorizontalAlignment="Left" ItemsSource="{Binding Items}" Width="300" Height="300" Style="{DynamicResource styleListView}" ItemContainerStyle="{DynamicResource styleListViewItem}">
      <GridView ColumnHeaderContainerStyle="{DynamicResource styleGridViewColumnHeader}">
          <GridViewColumn Header="Country" DisplayMemberBinding="{Binding [CSCD]}" />
          <GridViewColumn Header="Name" DisplayMemberBinding="{Binding [TX15]}" />
          <GridViewColumn Header="Currency" DisplayMemberBinding="{Binding [CUCD]}" />
    <Button Content="My Button" HorizontalAlignment="Left" Grid.Row="1" Margin="8,16,8,8" IsEnabled="{Binding Path=SelectedItem, ElementName=listViewCountries, Converter={StaticResource notNullConverter}}" />

1 thought on “Enable a button on a selected item

Comments are closed.