0

Ошибка не удается преобразовать тип void в int, что я неправильно делаю. Метод находится -

public class ModelCount : OnProperyChangedClass............
 public void Main(object obj)
    {
        CountInt = ob.Act();
    }


<Window
x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Test"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="250"
mc:Ignorable="d">
<Window.DataContext>
    <local:MainViewModel />
</Window.DataContext>
<Grid DataContext="{Binding AllModelCount}">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="50" />
    </Grid.RowDefinitions>
    <Label
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Content="{Binding CountInt}"
        FontSize="50" />
    <Button
        Grid.Row="1"
        Width="100"
        Height="50"
        Command="{Binding}"
        Content="Click" />
</Grid>

  public class ToModelCount
{
    int a = 50;
    int b = 50;
    int c;
    public void Act()
    {
        c = a + b;
    }
}

public class ModelCount : OnProperyChangedClass
{
    int countInt;
    ToModelCount ob = new ToModelCount();
    public int CountInt
    {
        get
        {
            return countInt;
        }
        set
        {
            countInt = value;
            OnAllPropertyChanged();
        }
    }
    public void Main(object obj)
    {
        CountInt = ob.Act();
    }
    ICommand command;
    public ICommand Command => command ?? (command = new RelayCommand(Main));
}

}

 public class MainViewModel : OnProperyChangedClass
{
    public ModelCount allmodelCount = new ModelCount();
    public ModelCount AllModelCount
    {
        get
        {
            return allmodelCount;
        }
        set
        {
            allmodelCount = value;
            OnAllPropertyChanged();
        }
    }
}

}

15
  • 1
    public void Act() и CountInt = ob.Act(); ?
    – tym32167
    10 апр 2019 в 19:32
  • Да - абсолютно верно. 10 апр 2019 в 19:33
  • тогда я не понял вопроса
    – tym32167
    10 апр 2019 в 19:36
  • 2
    ну это просто - void - это не int, и не может быть приведен к int. Собственно, void - не может быть приведен ни к чему, поскольку функция, помеченная как void, не возвращает ничего, даже пустого значения не возвращает.
    – tym32167
    10 апр 2019 в 19:50
  • 1
    я не знаю, что вы там читаете, но точно вам скажу, void вы никаким образом в int не превратите.
    – tym32167
    10 апр 2019 в 20:04

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.