'你调用的对象是空的。' lbl_Day为空

时间:2019-06-13 19:09:31

标签: c# asp.net wpf null

启动程序时,它显示“对象引用未设置为对象的实例。”

lbl_day为空。

我只想在wpf中更改标签的前景。但是,它在toggle_checked中发生了变化,但在toggle_unchecked中没有发生变化。

<Button Content="امکانات اصلی" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="130" Height="40"/>
<Button Content="امکانات تحصیلی" HorizontalAlignment="Left" Margin="180,10,0,0" VerticalAlignment="Top" Width="130" Height="40"/>
<Button Content="سایر امکانات" HorizontalAlignment="Left" Margin="354,10,0,0" VerticalAlignment="Top" Width="124" Height="40"/>
<Label  HorizontalAlignment="Right" x:Name="lbl_Saat" Content="00"   Height="27" Margin="0,19,35,0" VerticalAlignment="Top" Width="26" Foreground="Black"/>
<Label x:Name="lbl4"  HorizontalAlignment="Right" Content=":" Height="27" Margin="0,18,13,0" VerticalAlignment="Top" Width="16" Foreground="Black"/>
<Label  HorizontalAlignment="Right" x:Name="lbl_min" Content="00"   Height="27" Margin="0,19,19,0" VerticalAlignment="Top" Width="24" Foreground="Black"/>
<Label x:Name="lbl3"  HorizontalAlignment="Right" Content=":"   Height="27" Margin="0,18,31,0" VerticalAlignment="Top" Width="16" Foreground="Black"/>
<Label  HorizontalAlignment="Right" x:Name="lbl_Sanie" Content="00"  Height="27" Margin="0,19,0,0" VerticalAlignment="Top" Width="24" Foreground="Black"/>
<Label  HorizontalAlignment="Right" x:Name="lbl_Year" Content="00"  Height="27" Margin="0,18,79,0" VerticalAlignment="Top" Width="24" Foreground="Black"/>
<Label x:Name="lbl2"  HorizontalAlignment="Right" Content="/"  Height="28" Margin="0,18,93,0" VerticalAlignment="Top" Width="16" Foreground="Black"/>
<Label  HorizontalAlignment="Right" x:Name="lbl_month" Content="00" Height="27" Margin="0,18,99,0" VerticalAlignment="Top" Width="24" Foreground="Black"/>
<Label x:Name="lbl1"  HorizontalAlignment="Right" Content="/"  Height="27" Margin="0,18,112,0" VerticalAlignment="Top" Width="16" Foreground="Black"/>
<Label HorizontalAlignment="Right" x:Name="lbl_Day" Content="00"  Height="27" Margin="0,18,118,0" VerticalAlignment="Top" Width="24" Foreground="Black " />

private void ToggleButton_Checked(object sender, RoutedEventArgs e)
{   
    //Halate Rooz
    MainGrid.Background = Brushes.White;
    lbl_Day.Foreground = Brushes.Black;
    lbl_min.Foreground = Brushes.Black;
    lbl_month.Foreground = Brushes.Black;
    lbl_Saat.Foreground = Brushes.Black;
    lbl_Sanie.Foreground = Brushes.Black;
    lbl_Year.Foreground = Brushes.Black;
    lbl1.Foreground = Brushes.Black;
    lbl2.Foreground = Brushes.Black;
    lbl3.Foreground = Brushes.Black;
    lbl4.Foreground = Brushes.Black;
    btn_calendar.Foreground = Brushes.Black;
    btn_zaman.Foreground = Brushes.Black;
}

0 个答案:

没有答案