Binding between components with XAML and C#

Asked

Viewed 119 times

3

I need that when selecting an item in a combobox, the textbox is released for editing and its completion is required, as image below: inserir a descrição da imagem aqui

This Binding is being active by clicking on the new button, where I change the Isediting property of my Viewmodel class.

class ColectorsViewModel : Bindable
{
    bool isEditing;
    public bool IsEditing 
    {
        get { return isEditing; }
        set 
        {
            SetValue(ref isEditing, value);
            //ajusta o estado dos comandos
            NovoColetorCommand.CanExecute = IsViewing && selectedIndex >= 0;
            ExcluirColetorCommand.CanExecute = IsViewing && selectedIndex >= 0;
            CancelarEdicaoColetorCommand.CanExecute = isEditing;
            GravarColetorCommand.CanExecute = isEditing;
            // Notifica as properties IsEditing e IsViewing para serem reavaliadas.
            OnPropertyChanged("IsViewing");
        }
    }
}

in the XAML:

<TextBox x:Name="tbIntColetaVal" 
    Text="{Binding Colectors.IntervaloColetaVal, UpdateSourceTrigger=PropertyChanged}" 
    IsEnabled="{Binding IsEditing}" 
    HorizontalAlignment="Left" Height="23" 
    Margin="563,92,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="45" Grid.Column="1"
/>

and the Model:

public class Colectors : Bindable
{
    private int intervaloColetaVal;
    public int IntervaloColetaVal 
    {
        get { return intervaloColetaVal; }
        set 
        {
            SetValue(ref intervaloColetaVal, value);
            if (intervaloColetaVal <= 0)
            {
                AddError("O valor deve ser maior que zero(0)");
            }else
                RemoveErrors();
        }
    }
}
  • This command OnPropertyChanged("IsViewing"); should not be to notify change of property IsEditing?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.