Witam, mam poblem aplikacja nie chce się odpalić i wywala błąd:
System.NullReferenceException occurred
Message=Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
Poradzcie coś bo już próbuję to rozkminić 4h :/
private ICommand _dodajKwoteCommand;
public ICommand DodajKwote
{
get
{
if (_dodajKwoteCommand == null)
_dodajKwoteCommand = new RelayCommand(
(object argument) =>
{
decimal kwota = decimal.Parse(argument.ToString());
model.Dodaj(kwota);
OnPropertyChanged("Suma");
}
,
(object argument) =>
{
decimal kwota = decimal.Parse(argument.ToString()); // tu wywala błąd
return CzyLancuchKwotyJestPoprawny(kwota);
}
);
return _dodajKwoteCommand;
}
}
<Window x:Class="AsystentZakupow.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AsystentZakupow"
xmlns:mw="clr-namespace:AsystentZakupow.ViewModel"
mc:Ignorable="d"
Title="Asystent Zakupow" Height="200" Width="200">
<Window.DataContext>
<mw:ModelWidoku />
</Window.DataContext>
<Window.Resources>
<local:Converter x:Key="boolToBrush" />
<local:ConverterStringToDoublew x:Key="stringToDecimal" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Left" Grid.Row="0" FontSize="25"
Foreground="Navy" Margin="10"
VerticalAlignment="Top">
Suma:
<Run Foreground="Black" FontFamily="Courier New" Text="{Binding Suma, Mode=OneWay}"/>
</TextBlock>
<TextBox x:Name="tbKwota" Margin="10" Grid.Row="1" TextAlignment="Right"
Foreground="{Binding ElementName=btnDodaj, Path=IsEnabled, Mode=OneWay, Converter={StaticResource boolToBrush}}"
FontFamily="Courier New" Text="0" FontSize="30"/>
<Button x:Name="btnDodaj"
Margin="10" Grid.Row="2"
Command="{Binding DodajKwote}"
CommandParameter="{Binding ElementName=tbKwota, Path=Text, Converter={StaticResource stringToDecimal}}"
Content="Dodaj" FontSize="20" />
</Grid>
</Window>
grzesiek51114