Problem with Inotifypropertychanged C# WPF

Asked

Viewed 36 times

1

Guys I’m having a question, I’m messing with c# WPF vs2017, and I did the following: every class I put Inotifypropertychanged and added:

public event PropertyChangedEventHandler PropertyChanged;

    void OnPropertyChanged(string propName)
    {
        if (this.PropertyChanged != null)
            this.PropertyChanged(
                this, new PropertyChangedEventArgs(propName));
    }

then I did the ""test" I have 2 datagrid and 2 service lists (1 with the services already added and another available to be added), so when I click on a datagrid, it adds this service in the other list and removes from the available list. the problem is that it is not atulizing alone, I need to use again the bind command, follows the WPF

<DataGrid Name="GridListaDisponivel" 
                     Grid.ColumnSpan="20" 
                     Margin="5" 
                     Grid.RowSpan="7" 
                     Grid.Row="3"
                     CanUserAddRows="False"
                     CanUserReorderColumns="True"
                     AutoGenerateColumns="False" 
                     SelectionUnit="FullRow"
                     SelectionMode="Extended"
                     ItemsSource="{Binding Path=ListaServicoDisponivel, Mode = TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     SelectedValue="{Binding Path=Model, Mode = TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     IsReadOnly="True"
                     MouseLeftButtonUp="ListaServicoDisponivelOnMouseLeftClick"
              >
        <DataGrid.Columns>
            <DataGridTextColumn Width="0.2*" Binding="{Binding Codigo}" Header="Código"/>
            <DataGridTextColumn Width="0.8*" Binding="{Binding Descricao}" Header="Descrição"/>
        </DataGrid.Columns>
    </DataGrid>

    <Label Content="Serviços Cadastrados" Grid.ColumnSpan="20" Grid.Column="0" Grid.Row="11" Margin="-1,6,11,5"/>
    <DataGrid Name="GridListaCadastrado" 
                     Grid.ColumnSpan="20" 
                     Margin="5" 
                     Grid.RowSpan="7" 
                     Grid.Row="12"
                     CanUserAddRows="False"
                     CanUserReorderColumns="True"
                     AutoGenerateColumns="False" 
                     SelectionUnit="FullRow"
                     SelectionMode="Extended"
                     ItemsSource="{Binding Path=CartaoBean.Model.ListaServico, Mode = TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     IsReadOnly="True"
              >
        <DataGrid.Columns>
            <DataGridTextColumn Width="0.2*" Binding="{Binding Codigo}" Header="Código"/>
            <DataGridTextColumn Width="0.8*" Binding="{Binding Descricao}" Header="Descrição"/>
        </DataGrid.Columns>
    </DataGrid>

1 answer

1

Details are missing to give a more accurate answer, such as what kind of list you are using.

I’ll assume you’re adding Servico to a list List<Servico>.

If applicable, this class does not notify changes in your collection. To obtain the desired effect use ObservableCollection<Servico>.

For more information visit the following link

I hope I’ve helped.

  • thanks for the reply, the class is yes Observablecollection, so it could not be why it is not updating. Rodrigo

Browser other questions tagged

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