the code below
presents the error without any code referring to the System.NullReferenceException
1
dim w as mainwindow
Private Sub openbtn_Click(sender As Object, e As RoutedEventArgs) Handles openbtn.Click
Dim dlg As Microsoft.Win32.OpenFileDialog = New Microsoft.Win32.OpenFileDialog()
Dim result As Nullable(Of Boolean) = dlg.ShowDialog()
If result = True Then
My.Settings.Background = dlg.FileName
My.settings.save()
w.bgv()
End If
End Sub
2
Public Sub bgv()
Dim img = New ImageBrush
Dim exePath As String = My.Application.Info.DirectoryPath
img.ImageSource = New BitmapImage(New Uri(My.Settings.Background))
bacground.Background = img
XML MAIN WINDOW
<Window x:Name="home" x:Class="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:TV_OS_Project"
mc:Ignorable="d"
Title="MainWindow" Height="1080" Width="1920" WindowState="Maximized" WindowStyle="None">
<Window.Resources>
<ControlTemplate x:Key="Buttont" TargetType="{x:Type Button}">
<Grid>
<Rectangle x:Name="bac" Fill="#FFF4F4F5" HorizontalAlignment="Stretch" Height="Auto" Stroke="#FFF4F4F5" VerticalAlignment="Stretch" Width="Auto" RadiusY="19.5" RadiusX="19.5">
<Rectangle.Effect>
<DropShadowEffect Opacity="0.3"/>
</Rectangle.Effect>
</Rectangle>
<Image Height="Auto" Margin="15" VerticalAlignment="Stretch" Width="Auto" Source="globe_100px.png">
<Image.Effect>
<DropShadowEffect Opacity="0.2"/>
</Image.Effect>
</Image>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="bac" Property="Fill">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#f2f2f2" Offset="0"/>
<GradientStop Color="#b3b3b3" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="bac" Property="Stroke">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#f2f2f2" Offset="0"/>
<GradientStop Color="#b3b3b3" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<Grid x:Name="bacground">
<Grid.Background>
<ImageBrush ImageSource="tvos_back.jpg"/>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="0*"/>
</Grid.ColumnDefinitions>
<Grid Margin="0,0,-3,-3" Background="#99FFFFFF" Grid.ColumnSpan="2" Height="100" VerticalAlignment="Bottom">
<Grid.Effect>
<DropShadowEffect Direction="400" Opacity="0.5"/>
</Grid.Effect>
<Button x:Name="google" Content="Button" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Top" Width="65" Height="65" Template="{DynamicResource Buttont}"/>
<Button x:Name="youtube" Content="Button" HorizontalAlignment="Left" Margin="90,15,0,0" VerticalAlignment="Top" Width="65" Height="65" Template="{DynamicResource ButtonControlTemplate1}">
<Button.Resources>
<ControlTemplate x:Key="ButtonControlTemplate1" TargetType="{x:Type Button}">
<Grid>
<Rectangle x:Name="bac" Fill="#FFF4F4F5" HorizontalAlignment="Stretch" Height="Auto" Stroke="#FFF4F4F5" VerticalAlignment="Stretch" Width="Auto" RadiusY="19.5" RadiusX="19.5">
<Rectangle.Effect>
<DropShadowEffect Opacity="0.3"/>
</Rectangle.Effect>
</Rectangle>
<Image Height="Auto" Margin="15" VerticalAlignment="Stretch" Width="Auto" Source="play_button_100px.png">
<Image.Effect>
<DropShadowEffect Opacity="0.2"/>
</Image.Effect>
</Image>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="bac" Property="Fill">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#f2f2f2" Offset="0"/>
<GradientStop Color="#b3b3b3" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="bac" Property="Stroke">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#f2f2f2" Offset="0"/>
<GradientStop Color="#b3b3b3" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Resources>
</Button>
<Button x:Name="config" Content="Button" HorizontalAlignment="Left" Margin="1830,15,0,0" VerticalAlignment="Top" Width="65" Height="65" Template="{DynamicResource ButtonControlTemplate1}">
<Button.Resources>
<ControlTemplate x:Key="ButtonControlTemplate1" TargetType="{x:Type Button}">
<Grid>
<Rectangle x:Name="bac" Fill="#FFF4F4F5" HorizontalAlignment="Stretch" Height="Auto" Stroke="#FFF4F4F5" VerticalAlignment="Stretch" Width="Auto" RadiusY="19.5" RadiusX="19.5">
<Rectangle.Effect>
<DropShadowEffect Opacity="0.3"/>
</Rectangle.Effect>
</Rectangle>
<Image Height="Auto" Margin="15" VerticalAlignment="Stretch" Width="Auto" Source="settings_100px.png">
<Image.Effect>
<DropShadowEffect Opacity="0.2"/>
</Image.Effect>
</Image>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="bac" Property="Fill">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#f2f2f2" Offset="0"/>
<GradientStop Color="#b3b3b3" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="bac" Property="Stroke">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#f2f2f2" Offset="0"/>
<GradientStop Color="#b3b3b3" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Resources>
</Button>
</Grid>
<Grid x:Name="horas" HorizontalAlignment="Left" Margin="825,55,0,0" Width="270" Height="155" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="11*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="33*"/>
</Grid.ColumnDefinitions>
<Grid.Effect>
<DropShadowEffect Opacity="0.4" Direction="400"/>
</Grid.Effect>
<Rectangle Fill="#B2F4F4F5" RadiusY="19.5" RadiusX="19.5" Margin="5,0,10,20" Grid.ColumnSpan="3"/>
<Label x:Name="horas1" Content="00" HorizontalAlignment="Left" Margin="25,25,0,0" FontSize="72" Height="106" VerticalAlignment="Top" FontFamily="Arial" FontWeight="Bold" Foreground="#FF7A7A7A" Grid.ColumnSpan="3">
<Label.Effect>
<DropShadowEffect Opacity="0.2"/>
</Label.Effect>
</Label>
<Label x:Name="ponto" Content=":" HorizontalAlignment="Left" Margin="11,20,0,0" FontSize="72" Height="106" VerticalAlignment="Top" FontFamily="Arial" FontWeight="Bold" Foreground="#FF7A7A7A" RenderTransformOrigin="0.441,0.292" Grid.Column="2"/>
<Label x:Name="minutos" Content="00" HorizontalAlignment="Left" Margin="45,25,0,0" FontSize="72" Height="106" VerticalAlignment="Top" FontFamily="Arial" FontWeight="Bold" Foreground="#FF7A7A7A" Grid.Column="2">
<Label.Effect>
<DropShadowEffect Opacity="0.2"/>
</Label.Effect>
</Label>
</Grid>
</Grid>
</Window>
error type:
System.NullReferenceException