0
votes

I have a situation here.

I have one ListView with check boxes. check boxes are defined as data template. I have another stack panel and it contains one button. My requirement is that, initially when the window loads, none of the check boxes are selected and button should be disabled. when user clicks on any one of the checkbox, button should be enabled. when user unchecks all the checkboxes,button should be disabled.

i am using MVVM pattern with cattle framework.With the help of events,i could able achieve this functionality.

but my quesion is, can we able to handle this scenario in xaml itself. May be using triggers or converters?

I am new to WPF and no deep knowledge about WPF. Any help is appreciated.

I have tried using triggers. but since the checkboxes are inside ListView and defined as data template i am not able to access element name of checkbox from button style.

Rough outline is as follows

<ListView x:Name="MylistView" ItemsSource="{Binding Collection}" Height="250" 
              SelectionMode="Single" 
               BorderBrush="Transparent">
        <ListView.ItemTemplate>
            <DataTemplate>
                <CheckBox  x:Name="Checkbox" Content="{Binding Description}" IsChecked="{Binding IsEnable, Mode=TwoWay}" />
            </DataTemplate>
        </ListView.ItemTemplate>
</ListView>

<StackPanel Orientation="Horizontal">
        <Button x:Name="Save" Content="{l:Language Key=SAVE}" Width="50" Height="25" Margin="10" 
                 Command="{Binding Updpate, Source={StaticResource proxy}}">
<Button.Style>
//How do i refer checkbox from this level. I get only "Mylistview" control    at this level
   </Button.Style>
  </Button>
</StackPanel>

thanks in advance

1

1 Answers

1
votes

You have to declare a property Visibility with PropertyChanged event implemented as:

private bool _Visibility;
public bool Visibility
 { get 
      {
         return _Visibility ; 
      }
     set
      {
          _Visibility  = value;
           RaisePropertyChanged("Visibility");
      }
  }

internal void RaisePropertyChanged(string prop)
 {
     if (PropertyChanged != null)
      { 
        PropertyChanged(this, new PropertyChangedEventArgs(prop)); 
      }
 }


public event PropertyChangedEventHandler PropertyChanged;

Design

<Button Name="btnsdf"  Width="35" Height="35" Style="{DynamicResource MetroCircleButtonStyle}" ToolTip="Add Denomination"  >
     <Image Width="30" Source="/Images/icons/add.png"  Margin="0,1,0,0"></Image>
     <Button.Resources>
          <Style TargetType="Button">
               <Style.Triggers>
                    <DataTrigger Binding="{Binding Visibility,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="true">
                         Setter Property="Visibility" Value="Visible"></Setter>
                     </DataTrigger>
                     <DataTrigger Binding="{Binding Visibility,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="false">
                         <Setter Property="Visibility" Value="Collapsed"></Setter>
                     </DataTrigger>
                </Style.Triggers>
            </Style>
       </Button.Resources>
  </Button>

You need to set IsEnabled on Checkbox Checked and unchecked event. I hope this will give you an idea.