Disable interpolation of child elements in Windows RT - image

Right now I have a ScrollViewer control in a Windows Store Application which surrounds an Image element. I am trying to make a pixel art editor but when the ScrollViewer is zoomed in the Image's contents are interpolated. Is there currently any way to force the image to be scaled in nearest neighbor mode?
EDIT: I decided I should put some code to clarify what I'm trying to do, so here it is:
<ScrollViewer
x:Name="Container"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ZoomMode="Enabled"
MinZoomFactor="0.1"
MaxZoomFactor="100"
HorizontalScrollMode="Enabled"
HorizontalScrollBarVisibility="Auto"
VerticalScrollMode="Enabled"
VerticalScrollBarVisibility="Auto"
ViewChanged="OnContainerViewChanged">
<Border
x:Name="ImageBorder"
Width="32"
Height="32"
BorderBrush="White"
BorderThickness="4">
<Grid>
<Image
x:Name="RenderedImage"/>
<Image
x:Name="EditPreview"/>
<Canvas
x:Name="GridContainer"
Visibility="Collapsed"/>
<Rectangle
x:Name="InputCapturer"
Fill="Transparent"
PointerPressed="OnPointerPressed"
PointerMoved="OnPointerMoved"
PointerReleased="OnPointerReleased"
PointerExited="OnPointerLeave"/>
</Grid>
</Border>
</ScrollViewer>

Related

How to put a white border to Black ellipse in windows phone 8

I am using the above given popup in my windows phone 8 application. My issue is for the black color list item, it is not possible to differentiate the item from other items. So my question is how i can put a rounded white border to this particular black list item.
Here is the template what i am using in my application.
<DataTemplate x:Key="ColorListTemplate">
<Grid Height="70" Margin="0,0,0,5" toolkit:TiltEffect.IsTiltEnabled="True">
<StackPanel Orientation="Horizontal">
<Ellipse Height="52" Width="52" Fill="{Binding SelectedColor}"/>
<TextBlock Text="{Binding ColorName}" Margin="32,0" FontSize="34" Style="{StaticResource NormalText}"/>
<CheckBox IsChecked="{Binding CheckedStatus}" Style="{StaticResource CheckBoxStyle}" IsHitTestVisible="False"/>
</StackPanel>
</Grid>
</DataTemplate>
Anyone please help me to design my requirement.
You could set a colored Stroke on the Ellipse elements to make it stand out on the black background.
Example:
<Ellipse Height="52" Width="52" Fill="{Binding SelectedColor}" Stroke="White" StrokeThickness="1"/>

How to remove the border in Coding4Fun MessagePrompt

I followed this example to display my usercontrol inside Coding4Fun MessagePrompt.
http://windowsphonegeek.com/articles/Creating-a-Windows-Phone-7-Trial-Application-Adding-Buy-Now-Functionality
When the Home icon at the bottom of the page is clicked I open MessagePromt which has my UserControl with two buttons as shown in image below.
But for some reason there appears this light white border, I am unable to determine from where it is coming.
Note: I have set border Transparent and 0 thickness for my usercontorl and all controls inside it.
I just want to show the blue panel and no white border and it's width is 300 as what it is seen.
Does any one has any idea?
I got help from "Eric Fleck - Microsoft" on apphub forums. Here's his solution:
<phone:PhoneApplicationPage
...
xmlns:c4f="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls">
<phone:PhoneApplicationPage.Resources>
<ControlTemplate x:Key="MsgPropmtNoBorder" TargetType="c4f:MessagePrompt">
<Grid VerticalAlignment="Stretch">
<Rectangle Fill="{StaticResource TransparentBrush}" />
<Border VerticalAlignment="Top"
Margin="10"
Background="{TemplateBinding Background}"
BorderThickness="0"
BorderBrush="{StaticResource PhoneForegroundBrush}">
<StackPanel Margin="10">
<TextBlock
Text="{TemplateBinding Title}"
Margin="0,-10,-25,10"
FontSize="30"
TextWrapping="Wrap" FontFamily="Segoe WP Light" />
<ContentPresenter Content="{TemplateBinding Body}" />
<StackPanel
Margin="0,10,0,0"
Name="actionButtonArea"
Orientation="Horizontal"
HorizontalAlignment="Center" />
</StackPanel>
</Border>
</Grid>
</ControlTemplate>
</phone:PhoneApplicationPage.Resources>
MessagePrompt prompt = new MessagePrompt();
prompt.Body = new WPUC();
prompt.ActionPopUpButtons.Clear();
prompt.Overlay = new SolidColorBrush(Color.FromArgb(155, 41, 41, 41));
prompt.Template = (ControlTemplate)this.Resources["MsgPropmtNoBorder"];
prompt.Show();
Here's the resultant popup:
I played a bit with the MessagePrompt control, it couldn't found any way to disable or hide the border. It's a shadow kind of effect in MessagePrompt control to provide a popup like appearance.
However, Eventhough you cannot remove it, you can reduce it's effect by setting the Width property of the MessagePrompt equal to your actual blue UserControl ( 300 in this case).

Loading an image?

I have list box where I need to display image from the internet
I have a data-source like this:
and I bind "image" in listbox using DataTemplate like this:
<DataTemplate x:Key="DataTemplate1">
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Image Source="{Binding image}"></Image>
<TextBlock Text="{Binding imagedec}"></TextBlock>
</Grid>
</DataTemplate>
I am able to see the image but it comes late, what will be best way to display images in this situation?
This is because the image has to be loaded from the internet (or cache) first. Try adding a gray background as placeholder and set a fixed height and width:
<Border Background="{StaticResource PhoneInactiveBrush}" Width="100" Height="100">
<Image Source="{Binding image}" Stretch="UniformToFill" Width="100" Height="100" />
</Border>
This solution works only if you can set a fixed height and width...
UPDATE
You should use LowProfileImageLoader to improve performance:
http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx

WP7 ScrollViewer Bug When Content Height > 2000px

In my project, I use ScrollViewer to show some long height infomation.
I use like this:
<Grid Grid.Row="1" Height="630">
<ScrollViewer Background="Red" Grid.Row="1">
<Grid>
<Rectangle Height="3000" Fill="LightBlue" Width="440"/>
</Grid>
</ScrollViewer>
</Grid>
But, unfortunately, the rectangle does not show completely when scrollView bar's vertical height > 2000.
I have tested without Grid as ScrollViewer's content, only with Rectangle and the result is the same.
And the bug is also happens with Width.
Any you have any idea what's the workaround? How to deal with it?
This post is the same issue without any fixes.
The test full xaml is :
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<Grid Grid.Row="1" Height="630">
<ScrollViewer Background="Red" Grid.Row="1">
<Grid>
<Rectangle Height="3000" Fill="LightBlue" Width="440"/>
</Grid>
</ScrollViewer>
</Grid>
</Grid>
If it just a text, you could use this custom control: scrollable textblock. Otherwise, divide your content into blocks with size < 2048.
UPD:
2048px is a limit for GPU cached graphics. You can use a lot of controls (< 2048) inside a scrollviewer (total > 2048). In some cases all is fine, but in some it doesn't
For example:
<ScrollViewer Background="#4FFF6060">
<Grid Background="#FFFF8A8A" Width="240" HorizontalAlignment="Left" d:LayoutOverrides="Height">
<Rectangle Fill="Blue" Height="4000" VerticalAlignment="Top" Width="120" HorizontalAlignment="Left"/>
<Rectangle Fill="Red" Height="2000" VerticalAlignment="Top" Width="120" HorizontalAlignment="Right"/>
<Rectangle Fill="Red" Height="2000" VerticalAlignment="Top" Width="120" HorizontalAlignment="Right" Margin="0,2000,0,0"/>
</Grid>
</ScrollViewer>
In this case blue rectangle cropped at 2048px, but two rectangles with 2000px height placed one above the other looks fine.
The second example uses StackPanel to show 4000px area and it works too
<StackPanel Background="#FFFF8A8A" HorizontalAlignment="Right" Width="240" d:LayoutOverrides="Height">
<Rectangle Fill="#FF88FF00" Height="2000" Width="240" HorizontalAlignment="Right"/>
<Rectangle Fill="#FF88FF00" Height="2000" VerticalAlignment="Top" Width="240" HorizontalAlignment="Right"/>
</StackPanel>
Max. texture size on WP7 is 2048x2048. The rectangle height exceeds this limit. Once you decrease it below this limit, it starts working.
This code is better suited to experiments as you can identify bottom border:
<Grid Grid.Row="1" Height="630">
<ScrollViewer Background="Red" Grid.Row="1">
<Grid>
<Border Height="2048" BorderBrush="Blue" BorderThickness="5">
<Rectangle Height="2000" Fill="LightBlue" Width="440"/>
</Border>
</Grid>
</ScrollViewer>
</Grid>
Once you increase the Border height, the bottom part will disappear.
On the other hand, I have to say that this behavior surprises me, too. I would expect that system decomposes large objects into smaller textures, but apparently WP7 designers decided not to do so, but rather manifest UI bug.

Increase touchable target area of a small image?

In a listbox I have a list of titles with an edit icon next to each, how do I increase the touchable area so that even if the user touches part of the title, it actually triggers the image event?
I assume I need to wrap the image in another element but cannot work out what that needs to be.
I tried wrapping the image in a button and add padding to the button but then it pushed the UI elements around, I do not want to affect the presentation, just the none-visible touchable area.
Wrap it in a button - you're totally in the right ball-park. But you need to edit the control template of the button and reduce down all the standard padding and margin, borders etc. so its just a raw touchable region.
You can then wrap anything in this button and apply your template/style to make anything interactive.
Luke
You could try wrapping in a Panel or Grid.
Or just adjust the margin and Z-Order.
Put the image in a button, set the size of the button you want & then set the Stroke property to "No brush" on the button to remove the border.
Try it:
<Border BorderBrush="Transparent"
BorderThickness="20,25,20,0"
Background="Transparent">
<Grid/>
</Border>
or use it in other variations:
<Border Background="Transparent">
<Grid Margin="20 25 20 0"/>
</Border>
full sample with button: (no background interaction when pressed at this sample)
<Button BorderBrush="Transparent"
Tag="{Binding SelectedPhoto.commentsCount}">
<Button.Template>
<ControlTemplate>
<Border BorderThickness="20,25,20,0"
BorderBrush="Transparent"
Background="Transparent">
<StackPanel Orientation="Horizontal"
VerticalAlignment="Top">
<Grid Margin="0 0 4 0"
Visibility="{Binding CommentsAllowedForAlbum,Converter={StaticResource BoolToVisibilityConverter}}">
<TextBlock Text="{TemplateBinding Tag}"
Visibility="{Binding SelectedPhoto.HasComments,Converter={StaticResource BoolToVisibilityConverter}}"
Foreground="{StaticResource BlueColorBrush}"
FontSize="{StaticResource MFontSize36}" />
</Grid>
<Image Source="/Images/photo_comments_icon.png"
Stretch="Uniform"
MaxWidth="23"
Visibility="{Binding CommentsAllowedForAlbum,Converter={StaticResource BoolToVisibilityConverter}}"
Margin="0 7 0 0"
VerticalAlignment="Top" />
<Image Source="/Images/photo_comments_icon_blocked.png"
Stretch="Uniform"
MaxWidth="23"
Visibility="{Binding CommentsAllowedForAlbum,Converter={StaticResource OppositeBoolToVisibilityConverter}}"
Margin="0 7 0 0"
VerticalAlignment="Top" />
</StackPanel>
</Border>
</ControlTemplate>
</Button.Template>
</Button>

Resources