Hi everyone pleas help me i so confused why my code has a null after casting this is the xaml code i have
<Window.Resources>
<Style x:Key="Menu" TargetType="{x:Type Border}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Width" Value="25" />
<EventSetter Event="MouseLeftButtonUp" Handler="Menu_MouseLeftButtonUp" />
</Style>
</Window.Resources>
<Grid>
<Border Name="BorderCloseWindow" CornerRadius="0,8,0,0"
Style="{StaticResource Menu}">
<Image Source="pack://application:,,,/images/icons/CloseSTD.png" />
</Border>
</Grid>
and this the C# that handle the border
private void Menu_MouseLeftButtonUp(object sender, RoutedEventArgs e)
{
Border b = e.Source as Border;
if (b.Name == "BorderCloseWindow")
{
this.Close();
}
}
and if i mouse button down in the border that will give error like this Object reference not set to an instance of an object. that happen in
if(b.Name == "BorderCloseWindow")
please help me why that give null? and how to repair my program so can run.