How do I instate a class within a wpf?

Asked

Viewed 201 times

2

The thing goes beyond that, the problem is that it always returns this error by instantiating this class:

namespace AlmoxarifadoUpas
{
  class ConsultaMaterialEntradaSaida
  {
    private IEnumerable<MaterialA> materiais = new List<MaterialA>();

    private void adicionarMaterialAutoComplete()
    {
        using (Entities db = new Entities())
        {
            db.Configuration.ProxyCreationEnabled = false;
            var mate = from material in db.MaterialA
                       select material;
            materiais = mate.ToList();
        }
    }

    public IEnumerable<MaterialA> listaAutoComplete
    {
        get
        {
            adicionarMaterialAutoComplete();
            return materiais;
        }
    }
}
}

Error:

The name "Query" does not exist in the namespace "clr-namespace:"

I thought it was strange because this class is inside the namespace. In this case I went to test with another class, for example this DAO class (does not have the content of the methods because I did not find it necessary, and I wanted to simplify):

namespace AlmoxarifadoUpas
{
    class MaterialDAO : IMateriais
    {
        public void InserirMaterial(MaterialA material)

        public List<MaterialA> Listar()

        public bool VerificarSeCodigoExiste(string codigoMaterial)

        public void RemoverMaterial(MaterialA material)

        public void EditarMaterial(int id, string codigo, string nome, string unidade)

        public void EntradaDeMateriais(HistoricoMovimentacao historico)

        public void SaidaDeMateriais(HistoricoMovimentacao historico)

    }
}

I don’t know about you, but I didn’t find the difference, and just when I put this class up it doesn’t make the mistake, does anyone know what it might be? Follow below as I am instantiating in the shaman

    <DockPanel>
        <StackPanel x:Name="search" Orientation="Vertical">
            <StackPanel.Resources>
                <Style TargetType="{x:Type StackPanel}">
                    <Setter Property="Orientation" Value="Vertical" />
                    <Setter Property="Margin" Value="0,0,0,10" />
                </Style>
                <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="Margin" Value="0,0,0,6" />
                </Style>
                <DataTemplate x:Key="template">
                    <Border BorderBrush="White" BorderThickness="2" CornerRadius="3">
                        <Grid Background="White">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Text="Código:    "/>
                            <TextBlock Grid.Column="1" Text="{Binding codigo}" />
                            <TextBlock Grid.Row="1" Text="Material:     " />
                            <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding nome}"/>
                            <TextBlock Grid.Row="2" Text="Unidade:  " />
                            <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding unidade}" />
                            <TextBlock Grid.Row="3" Text="Saldo:  " />
                            <TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding saldo}" />
                        </Grid>
                    </Border>
                </DataTemplate>
                **<app:ConsultaMaterialEntradaSaida x:Key="listaMaterial" />**
            </StackPanel.Resources>

            <StackPanel>
                <Label Content="Pesquisar por nome" Target="{Binding ElementName=AutoCompleteNome}"/>
                <Grid >
                    <actb:AutoCompleteTextBox 
                            x:Name="AutoCompleteNome"
                            VerticalAlignment="Top"
                            Width="250"
                            ItemsSource="{Binding Source={StaticResource listaMaterial}, Path=listaAutoComplete}"
                            ItemTemplate="{StaticResource template}"
                            Binding="{Binding nome}" 
                            MaxCompletions="10" />
                </Grid>
            </StackPanel>
        </StackPanel>
    </DockPanel>

    <DockPanel Grid.Row="1">
        <ScrollViewer>
            <StackPanel MinWidth="400">
                <TextBlock Text="Incluir entrada de insumos" Style="{StaticResource Heading2}" Margin="0,0,0,8" />
                <StackPanel x:Name="Form" Orientation="Vertical">

                    <StackPanel.Resources>
                        <Style TargetType="{x:Type StackPanel}">
                            <Setter Property="Orientation" Value="Horizontal" />
                            <Setter Property="Margin" Value="0,0,0,10" />
                        </Style>
                        <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
                            <Setter Property="Width" Value="200" />
                            <Setter Property="VerticalAlignment" Value="Center" />
                        </Style>
                    </StackPanel.Resources>
                    <!-- create viewmodel -->
                    <StackPanel.DataContext>
                        <app:MainWindow />
                    </StackPanel.DataContext>

                    <StackPanel>
                        <Label Content="Origem" Target="{Binding ElementName=TextOrigem}"/>
                        <TextBox x:Name="TextOrigem" Width="150" Text="{Binding Origem, Mode=TwoWay, ValidatesOnDataErrors=True}" />
                    </StackPanel>
                    <StackPanel>
                        <Label Content="Destino" Target="{Binding ElementName=TextDestino}"/>
                        <TextBox x:Name="TextDestino" Width="150" Text="{Binding Destino, Mode=TwoWay, ValidatesOnDataErrors=True}"/>
                    </StackPanel>
                    <StackPanel>
                        <Label Content="Quantidade movimentada" Target="{Binding ElementName=TextMovimento}"/>
                        <TextBox x:Name="TextMovimento" Width="150"/>
                    </StackPanel>
                    <Button Content="Confirmar" Margin="200,16,0,0" HorizontalAlignment="Left" Click="Button_Click" />
                </StackPanel>
                <!-- actual form starts here -->
            </StackPanel>
        </ScrollViewer>
    </DockPanel>
</Grid>

  • 1

    For future reference: es·tan·ci·ar: Stay, reside; stop; linger; rest. ins·tan·ci·ar: Provide the concrete instance of something; in programming, create a concrete instance, an object of a given class. The correct is "as I instate a class".

  • The project is on your machine or network?

  • @Igorventurelli in my machine !

  • Already tried to close and open Visualstudio, clean the project and then rebuild?

  • @Igorventurelli Well, by miracle it worked when I did this, I think it’s on account of I’m using a this search textbox plugin. But it finally worked !

1 answer

0


Solved by giving Clean in the project and closing the visual studio, but as I am using a plugin to search inside the textbox, it is not working completely, so I did everything manually same !

Browser other questions tagged

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