Image won't Display - vb.net

I have an image on my WPF form. It displays fine in the IDE but when I run it, its not there. Nor is the tooltip.
I've tried both .png and .jpg. Its marked as visible.
<Grid>
<Image x:Name="imgLogo" HorizontalAlignment="Left" Height="54" Margin="301,18,0,0" VerticalAlignment="Top" Width="194" Source="pack://siteoforigin:,,,/Resources/Logo.jpg" Stretch="None" ToolTip="Logo"/>
<Label x:Name="lblTitle" Content="Task Utility" HorizontalAlignment="Left" Margin="32,16,0,0" VerticalAlignment="Top" FontSize="22"/>
<Button x:Name="btnExit" Content="Exit" HorizontalAlignment="Left" Height="68" Margin="33,517,0,0" VerticalAlignment="Top" Width="94" Background="#FFD9422A" Foreground="#FFF7F3F3" FontSize="18" FontWeight="Bold" BorderThickness="0" RenderTransformOrigin="-2.202,0.456"/>
......
</Grid>
Any ideas? All the other elements (buttons, data grids, labels etc) work fine.

Do you have a /Resources/Logo.jpg file relative to the folder where the debug folder or compiled application resides?
For example if the app is located at: C:\myapp\myapp.exe then the image should be in C:\myapp\Resources\Logo.jpg

Related

Windows Phone StackPanel control alternative for Xamarin Forms?

I prototyped an app in Windows Phone 8.1 (WP) I was able to create cool controls using the which would allow me to put Labels and other controls inside a button and this would glue them all together.
I am now rebuilding the app in Xamarin.Forms (XF).
I am working around this issue for the time being in XF by using Absolute Layout but I fear and I am expecting this to fall apart over differnt phones, sizes and models.
I am certainly sure I am not the first to have this problem so I'm wondering how others have gotten around it.
Thank you :)
What I like doing in WP:
<Button Height="200" HorizontalAlignment="Left" Margin="232,1,0,0" Name="BtnVisitorScore" VerticalAlignment="Top" Width="220" Click="btnVisitorScore_Click" Grid.Row="1">
<StackPanel Margin="-5,-30,0,0" >
<TextBlock Text="{Binding MatchSettings.VisitingTeam.Name}" Height="40" HorizontalAlignment="Left" Width="180" FontSize="18" FontFamily="Arial" TextAlignment="Center" />
<TextBlock Text="{Binding VisitingTeamCurrentScore, StringFormat=N0}" Height="70" Width="180" FontSize="72" FontFamily="Arial" TextAlignment="Center" VerticalAlignment="Top" />
</StackPanel>
</Button>

How do I create a two column layout using xaml RelativePanel?

I'd really like to use RelativePanel in a UWP app I'm writing, to simplify visual state.
This is what I want
I've tried to achieve this with the following XAML:
<RelativePanel>
<TextBlock x:Name="Title" Height="50" Margin="15" FontSize="24"
RelativePanel.AlignTopWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True">
</TextBlock>
<TextBox x:Name="Editor" Margin="15" Padding="20" HorizontalAlignment="Stretch"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below="Title"
RelativePanel.RightOf="FileList">
</TextBox>
<ListView x:Name="FileList" HorizontalAlignment="Stretch" Margin="15"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.Below="Title">
</ListView>
</RelativePanel>
This isn't working. Editor does not stretch. If I set Editor to RelativePanel.AlignRightWith="FilesList", it stretches past files list and fills the window.
Is there any way to do what I want with RelativePanel? Please don't post suggestions on how to do this in Grid, I can already do that - I want to use RelativePanel in this case
Your Editor control should have -
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below="Title"
RelativePanel.LeftOf="FileList"
RelativePanel.AlignBottomWithPanel="True"
Note it should be LeftOf, not RightOf. You will also need AlignBottomWithPanel set to True.

Adding A Background Image In XAML

I am very new to XAML code, but I want to try and code a personal program. I have started with XAML but anything I add does not show up. Here is my code:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Home" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="7,725,0,0" Height="36" Width="91" BorderBrush="Orange" Foreground="Orange" FontFamily="BankGothic Md Bt"/>
<Image HorizontalAlignment="Left" Height="768" VerticalAlignment="Top" Width="1366" Source="C:/Users/Flynn/Desktop/BG.gif" Visibility="Visible"/>
</Grid>
</Page>
The button nor the image is showing up when I run the program. Can someone point me in the right direction? Thanks for your help!
To set a background to a grid, just keep your image in Images folder and add this code inside grid
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="..\Images\background.jpg" AlignmentY="Top" AlignmentX="Center"/>
</Grid.Background>
Please try this code.It works
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Home" HorizontalAlignment="Left" VerticalAlignment="Top" Height="36" Width="91" BorderBrush="Orange" Foreground="Orange" FontFamily="BankGothic Md Bt"/>
<Image Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center" Source="Images/super.jpg"/>
</Grid>
You should define the background property like this
You must add in to App.xaml (for color resource)
<Application.Resources>
<SolidColorBrush x:Key="ApplicationPageBackgroundThemeBrush" Color="BlueViolet"/>
</Application.Resources>
Image source have to be in your solution (application)

XAML: WebBrower Background Color?

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBox HorizontalAlignment="Left" Name="number" Height="72" TextWrapping="Wrap" VerticalAlignment="Top" Width="240" Margin="24,0,0,0" InputScope="Number" MaxLength="3" />
<Button Content="find" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="269,0,0,0" Width="161" RenderTransformOrigin="0.743,0.541" Name="searchbutton" Click="search"/>
</Grid>
<Grid Grid.Row="1" Margin="0,84,0,0" Grid.RowSpan="2">
<phone:WebBrowser x:Name="browser" IsScriptEnabled="True" Background="Black" Foreground="Black"/>
</Grid>
Here is my xaml code for initializing web browser in my app. But, the web browser appears in white color. I have given all coloring properties as much i know. But it stills in same white color. I need to make it transparent.
Here's my sample image files I captured - http://img829.imageshack.us/img829/6956/rt0n.png
Best answer will be much appreciated.
You can change the background color for webbrowser. Just look at this answer
How to make Webbrowser control with black background in Windows Phone 7.1

How to access a control present inside a datatemplate of listbox in metro app?

I am developing a windows 8 metro app in which I have listbox which contains a set of textblocks and a Image.
<ListBox x:Name="lstbxbStudents" Background="Transparent" ItemContainerStyleSelector="{StaticResource ItemStyleSelector}" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{StaticResource LandscapeItemTemplate}" Height="476" SelectionChanged="lstbxbProducts_SelectionChanged_1" Style="{StaticResource ListBoxStyle1}" HorizontalAlignment="Left" Width="901">
</ListBox>
For that image ImgCmt I have set the source of the Image static inside the datatemplate of the listbox.
<Page.Resources>
<CollectionViewSource x:Name="cvs2" IsSourceGrouped="true" />
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
<x:String x:Key="AppName">Students Screen</x:String>
<DataTemplate x:Key="LandscapeItemTemplate" >
<StackPanel Orientation="Horizontal">
<StackPanel Width="30"></StackPanel>
<StackPanel Width="120" Orientation="Horizontal">
<TextBlock Text="{Binding stunum}" VerticalAlignment="Center" HorizontalAlignment="Left" />
</StackPanel>
<StackPanel Width="350">
<TextBlock Text="{Binding studsc}" HorizontalAlignment="Left" />
</StackPanel>
<StackPanel Width="10"></StackPanel>
<StackPanel Width="100">
<TextBlock Text="{Binding stuum}" x:Name="txtblkstuum" HorizontalAlignment="Left" />
</StackPanel>
<StackPanel Width="150">
<TextBlock Text="{Binding stugrp}" VerticalAlignment="Center" TextAlignment="Right" HorizontalAlignment="Center" />
</StackPanel>
<StackPanel Width="100">
<TextBlock Text="{Binding stusection, Mode=TwoWay}" TextAlignment="Center" x:Name="txtbxbstusection" Tag="{Binding stunum}" VerticalAlignment="Center" HorizontalAlignment="Right" />
</StackPanel>
<StackPanel Width="50"></StackPanel>
<StackPanel>
<Image Source="Assets/comments.png" Name="ImgCmt" PointerPressed="Image_PointerPressed_1" VerticalAlignment="Center" Width="20" Height="20"></Image>
</StackPanel>
</StackPanel>
</DataTemplate>
</Page.Resources>
my objective is that I want to change the source of the image to different image source(change the image) in codebehind depnding upon some condition for that I need to access the control present inside a datatemplate of listbox in metro app ?
How can I do this :
How to access a control present inside a datatemplate of listbox in metro app?
What are the different ways in which I can do this?
How can I change the source of the image to different image source(change the image) in codebehind depending upon some condition?
This is a common question. We've all asked it at least once. The problem is that these controls don't have a unique name, because they are in a repeater. As a result, you cannot use the logical tree in XAML. The logical tree is what lets you call things by name. Instead, you need to use the visual tree in XAML. The visual tree is what lets you access everything on the screen including the dynamically rendered elements that adorn controls and populate repeaters. Because the visual tree is so big and because a repeater repeats, you still have to constrain the scope of the visual tree so you can reliably locate the control you want to find. I hope this makes sense.
Solution here: http://blog.jerrynixon.com/2012/09/how-to-access-named-control-inside-xaml.html