I have added an Image inside a Canvas view with this code.
<Canvas x:Name="ContentPanelCanavas" Background="Transparent"
Height="{Binding ActualHeight, ElementName=LayoutRoot}"
Width="{Binding ActualWidth, ElementName=LayoutRoot}">
<Image x:Name="StartLogo" Source="/Assets/test.png" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Canvas>
But the Image is going out of View.
What is going wrong here. Please help
Canvas was designed to work like that. Consider using other UIElements or if you insist on using Canvas then one of the solutins may be to set Binding in Width/Height of the Image:
<Canvas x:Name="ContentPanelCanavas" Background="Transparent"
Height="{Binding ActualHeight, ElementName=LayoutRoot}"
Width="{Binding ActualWidth, ElementName=LayoutRoot}">
<Image Width="{Binding ElementName=ContentPanelCanavas, Path=ActualWidth}"
Height="{Binding ElementName=ContentPanelCanavas, Path=ActualHeight}"
x:Name="StartLogo" Source="/Assets/test.png" Stretch="Uniform"
VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Canvas>
Of course you can bind to Canvas (as above) or to LayoutRoot. Also define how the Image should be streched (if Uniform or UniformToFill).
You are needed to set Height n Width of image n the Stretch Property to Fill for it doesnt go out of Your Canvas
<Canvas x:Name="ContentPanelCanavas" Background="Transparent"
Height="{Binding ActualHeight, ElementName=LayoutRoot}"
Width="{Binding ActualWidth, ElementName=LayoutRoot}">
<Image x:Name="StartLogo" Source="/Assets/test.png" Stretch="Fill" VerticalAlignment="Center" HorizontalAlignment="Center" Height="{Binding ActualHeight, ElementName=LayoutRoot}"
Width="{Binding ActualWidth, ElementName=LayoutRoot}"/>
</Canvas>
try this.
<Image Name="StartLogo" Source="/Assets/image.png"
Height="{Binding ActualHeight, ElementName=LayoutRoot}"
Width="{Binding ActualWidth, ElementName=LayoutRoot}"
Stretch="Fill"></Image>
OR
<Grid Width="..." Height="...">
<Image Name="StartLogo" Source="/Assets/image.png"
Stretch="Fill" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></Image>
</Grid>
Hope this helps.....
This is the default behavior of a Canvas. When you change the Canvas into a StackPanel it will work:
<Stackpanel x:Name="ContentPanelCanavas" Background="Transparent"
Height="{Binding ActualHeight, ElementName=LayoutRoot}"
Width="{Binding ActualWidth, ElementName=LayoutRoot}">
<Image x:Name="StartLogo" Source="/Assets/test.png" Stretch="Fill" />
</Stackpanel>
Related
I need to place images side by side and need to place one small image icon below the each image.please help me how to design ?any samples please let me know..
How to place userimage inside one small image dynamically based on condition..please help me..
I made simple prototype for you. I can't make whole screen for you. Here are the basic things as I got from your comments and screenshot. Please see XAML and screenshot below:
<ListBox Name="lstImages" VerticalAlignment="Top">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="0,0,0,-15" />
<Setter Property="Margin" Value="2"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel>
</toolkit:WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Height="100" Width="110" Source="{Binding BigImageSource}" VerticalAlignment="Top"/>
<Image Height="10" Width="10" Source="{Binding SmallImageSource}" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,-35,10,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Use this
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Image Source="Your image" Grid.Row="0"/>
<Image Source="Your small icon" Grid.Row="1"/>
</Grid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Image Source="Your image" Grid.Row="0"/>
<Image Source="Your small icon" Grid.Row="1"/>
</Grid>
</Grid>
<StackPanel>
<StackPanel Orientation="Horizontal">
<Image Source="Firstimage" />
<Image Source="Secondimage" />
</Stackpanel>
<StackPanel Orientation="Horizontal">
<Image Source="Firsticon" />
<Image Source="Secondicon" />
</Stackpanel>
</StackPanel>
But here you have to make some changes to the icon stackpanel like setting some margin, inorder to make it aligned to the actual images.
This is just an alternative, you can also use Grid's as answered by nucleons
If you want to show your images in listbox then wrap this way in wrap panel and you can set direction of wrappanel as well. Wrappanel is found in silverlight toolkit of windows phone 7.
<ListBox Name="lstImages">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="-15" />
<Setter Property="Margin" Value="0"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel>
</toolkit:WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<stackpanel>
<Image Source="Your image" />
<Image Source="Small image" />
</stackpanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
and bind this listbox with your collection of data.
hei,
assume that i have this code:
<StackPanel>
<Canvas x:Name="canvas" Height="400" Width="235">
<Image x:Name="image" Source="/SplashScreenImage.jpg" Stretch="Fill">
<Image.RenderTransform>
<CompositeTransform ScaleX="0.5" ScaleY="0.5"/>
</Image.RenderTransform>
</Image>
<TextBlock Canvas.ZIndex="1" Text="TextBlock" Canvas.Left="61" Canvas.Top="150"/>
</Canvas>
<TextBlock HorizontalAlignment="Center" >Test</TextBlock>
</StackPanel>
What i want to do is the canvas's width and height properties linked to image. something like this:
<Canvas x:Name="canvas" Height="{image Height}" Width="{image Width"}>
since I have been previously using Qt Quick and this is quite easy, they call it property binding. I am wondering if this is possible in XAML as well ?
Thanks.
I think I found the solution, example:
<StackPanel>
<TextBox Margin="10" x:Name="txtData" />
<TextBlock Margin="10"
Text="{Binding ElementName=txtData,
Path=Text}" />
</StackPanel>
I tried to overlap the border with an image inside but i found it unable to apply while i saw some application are able to do so. Any idea?
<Border BorderBrush="White" BorderThickness="1" Margin="20,20" Height="120" Width="410" >
<StackPanel Orientation="Horizontal">
<Canvas>
<Image Margin="-30,0,0,45" VerticalAlignment="Top" Source="{Binding Path=ListboxImage}" Width="100" Height="150" />
</Canvas>
<StackPanel>
<TextBlock Margin="135,8" Width="300" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left" Text="{Binding Path=ListboxName}" FontSize="{StaticResource PhoneFontSizeExtraLarge}"/>
<TextBlock Margin="150,0,0,8" Width="300" VerticalAlignment="Top" HorizontalAlignment="Left" Text="{Binding Path=ListboxDescription}" />
</StackPanel>
</StackPanel>
</Border>
While i tried to add some shadow effect to the border.
<Border>
<Border.Effect>
.......
</Border.Effect>
</Border>
but it seem to be doesn't support the effect.
+ I found some forum said that they took off the effect due to performance~
Any idea how to do so?
Hi I find it for you man... Try this you can get overlapped image in the border
<ListBox ItemsSource="{Binding alldata}" Height="500" HorizontalAlignment="Left" Margin="12,160,0,0" Name="listBox3" VerticalAlignment="Top" Width="438" Background="Black">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" BorderBrush="White">
<StackPanel Height="250" Orientation="Vertical" Name="stackPanel1" Width="400" >
<Border Margin="30,40,0,120" BorderThickness="1" BorderBrush="White">
<Canvas Height="100">
<TextBlock Text="Catalogue" Margin="160,50"> </TextBlock>
</Canvas>
</Border>
<Image Height="150" Width="160" Margin="-400,-400,-200,0" Source="{Binding image}">
</Image>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
in mainpage.cs add the code
Uri uri = new Uri("http://d1mu9ule1cy7bp.cloudfront.net/2012/media/catalogues/47/pages/p_"+ i +"/thump.jpg", UriKind.Absolute);
ImageSource imgSource = new BitmapImage(uri);
Image image = new Image();
alldata data = new alldata(){image = img.source, text = "catalogue"};
public class alldata
{
public imagesource image
public string text
}
Try to have a rectangle and image inside a stack
<StackPanel Orientation="Horizontal">
<border>
<rectangle height="50">
<textblock text={}>
</rectangle>
</border>
<Image Margin="-30,0,0,45" height = "75"/>
</Stackpanel>
Try to align the margin of image to be in the left of stackpanel and the rectangle height should be less than the image height.Try to reduce the corner radius of rectangle this also helps.
I'm trying to scroll a large textblock horizontally. I tried couple of the following way. None of the works for me. Can anyone tell me how to do it?
Try 1:-
<Canvas x:Name="myCanvas" Height="590" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="700">
<ScrollViewer x:Name="sv" Canvas.Left="1" Canvas.Top="520" HorizontalScrollBarVisibility="Auto">
<TextBlock Canvas.Left="2" Canvas.Top="522" Height="62" Name="textBlock1" Text="TextBlockTextBlockTextBlockTextBlockTextBlockTextBlock111111222222" Width="590" />
</ScrollViewer>
</Canvas>
Try 2:-
<Canvas x:Name="myCanvas" Height="590" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="700">
<StackPanel Orientation="Horizontal" Canvas.Left="1" Canvas.Top="520" Height="100" Name="stackPanel1" Width="635">
<ScrollViewer x:Name="sv" Margin="1,1,1,1" HorizontalScrollBarVisibility="Auto">
<TextBlock Canvas.Left="2" Canvas.Top="522" Height="62" Name="textBlock1" Text="TextBlockTextBlockTextBlockTextBlockTextBlockTextBlock111111222222" Width="590" />
</ScrollViewer>
</StackPanel>
Try 3:-
<Grid Canvas.Left="1" Canvas.Top="500" Height="200" Name="grid1" Width="640">
<StackPanel Orientation="Horizontal" Canvas.Left="1" Canvas.Top="500" Height="100" Name="stackPanel1" Width="635">
<ScrollViewer x:Name="sv" Margin="1,1,1,1" HorizontalScrollBarVisibility="Auto">
<TextBlock Canvas.Left="2" Canvas.Top="500" Height="62" Name="textBlock1" Text="TextBlockTextBlockTextBlockTextBlockTextBlockTextBlock111111222222" Width="590" />
</ScrollViewer>
</StackPanel>
</Grid>
<Grid x:Name="LayoutRoot" Background="Transparent">
<ScrollViewer HorizontalScrollBarVisibility="Visible">
<TextBlock Width="1000" Height="500" TextWrapping="Wrap" Text="asasdgasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf" />
</ScrollViewer>
</Grid>
If I understood correctly this should solve your problem.
I hope someone can help with what should be a very simple problem to solve... I've spent hours on this and it's just driving me crazy!
In my Silverlight WP7 app I have a ScrollViewer control that is 600x600 and offset to the left by 60 pixels (to center it horizontally) and in this I have a number of images overlayed on each other (see the code below).
I also have a Popup control defined which pops up while the images are downloading from the web but I just can't get the PopUp centered - and even worse, the text inside it is NEVER centered even though I've specified it to be... it always justifies left no matter what I try.
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="600"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="1" Margin="-60,0,0,0" Height="600" Width="600" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
<Grid x:Name="RadarImages" Margin="0,0,0,0">
<Image Height="600" Margin="0,0,0,0" HorizontalAlignment="Left" Name="imgBack" Stretch="Fill" VerticalAlignment="Top" Width="600" Opacity="100" />
<Image Height="600" Margin="0,0,0,0" HorizontalAlignment="Left" Name="imgObs" Stretch="Fill" VerticalAlignment="Top" Width="600" Opacity="100" />
<Image Height="600" Margin="0,0,0,0" HorizontalAlignment="Left" Name="imgLoop" Stretch="Fill" VerticalAlignment="Top" Width="600" Opacity="100" />
<Popup x:Name="StatusPopup" Margin="-200,-100,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox Text="...loading..." Width="200" Height="60" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Black" Foreground="White" BorderBrush="White" BorderThickness="3" />
</Popup>
</Grid>
</ScrollViewer>
</Grid>
I've tried adding a Grid inside the popup to explicitly control the layout with no joy: the darned PopUp just won't center on the screen and the text inside won't either.
Can anybody suggest what I need to do to fix this?
TIA...
Mike
I've managed to get the Popup content using the following XAML (I added a couple of fixed background colors to show where different elements are):
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="600"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="1" Margin="-60,0,0,0" Height="600" Width="600" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
<Grid x:Name="RadarImages" Background="AliceBlue" Margin="0,0,0,0">
<Image Height="600" Margin="0,0,0,0" HorizontalAlignment="Left" Name="imgBack" Stretch="Fill" VerticalAlignment="Top" Width="600" Opacity="1" />
<Image Height="600" Margin="0,0,0,0" HorizontalAlignment="Left" Name="imgObs" Stretch="Fill" VerticalAlignment="Top" Width="600" Opacity="1" />
<Image Height="600" Margin="0,0,0,0" HorizontalAlignment="Left" Name="imgLoop" Stretch="Fill" VerticalAlignment="Top" Width="600" Opacity="1" />
<Popup x:Name="StatusPopup" IsOpen="True">
<Border Background="Red" Height="768" Margin="60,0" Width="480">
<TextBox Text="...loading..." HorizontalAlignment="Center" VerticalAlignment="Center" Background="Black" Foreground="White" BorderBrush="White" BorderThickness="3" />
</Border>
</Popup>
</Grid>
</ScrollViewer>
</Grid>
Bascially, you can't use the Popup itself for position or alignment, you have to work with the root element inside the Popup instead.
One other thing: the valid range of values for Opacity are 0 to 1, not 100.