Hello everyone, I salute me, I am so confused why my code is zero after casting this is 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 is 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 click the mouse button on the border, which will give an error similar to this, the object instance does not have a reference to the object. which occur in
if(b.Name == "BorderCloseWindow")
Please help me, why does this give null? and how to restore my program so that you can work.
source
share