In a windows phone 8.1 runtime app I need to crop an image using a circle, to doing this i have used this code:
<Ellipse x:Name="ellipse" Stroke="White" StrokeThickness="1" StrokeDashArray="3,3" Height="300" Width="300" Canvas.ZIndex="1" VerticalAlignment="Center" HorizontalAlignment="Center" >
<Ellipse.Fill>
<ImageBrush Stretch="UniformToFill" ImageSource="{Binding Source, ElementName=image}"/>
</Ellipse.Fill>
</Ellipse>
<Grid Background="Black" >
<Image x:Name="image" Source="ms-appx:///Assets/avatar.png" VerticalAlignment="Center" Stretch="UniformToFill" HorizontalAlignment="Center" Height="300" Opacity="0.5" />
</Grid>
this is the result:
for render the ellipse i use this code:
var bitmap = new RenderTargetBitmap();
await bitmap.RenderAsync(ellipse);
I have to let the user translate and zoom this image, how can i manipulate those 2 images in a way that they looks one image?
Ok so after variour research and various test this is the solution to my problem.
With tis code you can handle full manipulation event including rotation zoom and translation!
XAML:
<Grid x:Name="LayoutRoot" Background="Black">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" x:Name="ContentRoot" RenderTransformOrigin="0.5,0.5" Opacity="0.5" >
<Image x:Name="Image" Source="ms-appx:///Assets/AccountManagement/avatar.png" VerticalAlignment="Center" Stretch="UniformToFill" ScrollViewer.HorizontalScrollBarVisibility="Visible" HorizontalAlignment="Center" Height="300" RenderTransformOrigin="0.5,0.5" >
<Image.RenderTransform>
<CompositeTransform x:Name="ImageCompositeTransform" Rotation="0" TranslateX="0" TranslateY="0" ScaleX="1" ScaleY="1" />
</Image.RenderTransform>
</Image>
</Grid>
<Ellipse ManipulationDelta="Ellipse_ManipulationDelta" x:Name="Ellipse" Stroke="White" StrokeThickness="1" StrokeDashArray="3,3" Height="300" Width="300" Canvas.ZIndex="1" Margin="0" Grid.Row="1" VerticalAlignment="Center" d:LayoutOverrides="Height" HorizontalAlignment="Center" ManipulationMode="All" RenderTransformOrigin="0.5,0.5" >
<Ellipse.Fill>
<ImageBrush Stretch="UniformToFill" ImageSource="{Binding Source, ElementName=Image}">
<ImageBrush.Transform>
<CompositeTransform CenterX="150" CenterY="150" ScaleX="{Binding ScaleX, ElementName=ImageCompositeTransform}" ScaleY="{Binding ScaleY, ElementName=ImageCompositeTransform}" TranslateX="{Binding TranslateX, ElementName=ImageCompositeTransform}" TranslateY="{Binding TranslateY, ElementName=ImageCompositeTransform}" Rotation="{Binding Rotation, ElementName=ImageCompositeTransform}" />
</ImageBrush.Transform>
</ImageBrush>
</Ellipse.Fill>
</Ellipse>
</Grid>
C#:
private void Ellipse_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
ImageCompositeTransform.ScaleX *= e.Delta.Scale;
ImageCompositeTransform.ScaleY *= e.Delta.Scale;
ImageCompositeTransform.Rotation += e.Delta.Rotation / Math.PI;
ImageCompositeTransform.TranslateX += e.Delta.Translation.X;
ImageCompositeTransform.TranslateY += e.Delta.Translation.Y;
}
Related
I am using trial version of SciChart and doing some tests.
I need to bring scroll bar on top of X axis.
After some research and parsing visual tree, I am planning to change style of SciChartSurface and replace axis and scroll bar, which are placed inside stack panel.
Is this right solution? If AxisAlignment is Top, visual tree may differ.
If this is right way to go, where can I find style of surface?
Bland does not recognize chart and I can't use it.
I was playing around with this and it is possible to achieve a scrollbar above an XAxis by templating the axis control itself.
Here is the default control template for the AxisBase control (SciChart v4)
<ControlTemplate TargetType="axes:AxisBase">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
ap:Device.SnapsToDevicePixels="True">
<StackPanel x:Name="PART_AxisContainer"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Orientation="{Binding AxisAlignment, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, Converter={StaticResource AxisAlignmentToAxisOrientationConverter}, ConverterParameter=Inverse}"
ap:Device.SnapsToDevicePixels="True"
apc:AxisLayoutHelper.AxisAlignment="{Binding AxisAlignment, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Canvas.ZIndex="1"
ap:Device.SnapsToDevicePixels="True"
apc:AxisLayoutHelper.IsInsideItem="True">
<themes:AxisPanel x:Name="PART_AxisCanvas"
AxisAlignment="{TemplateBinding AxisAlignment}"
Background="Transparent"
DrawLabels="{TemplateBinding DrawLabels}"
DrawMajorTicks="{TemplateBinding DrawMajorTicks}"
DrawMinorTicks="{TemplateBinding DrawMinorTicks}"
IsLabelCullingEnabled="{TemplateBinding IsLabelCullingEnabled}"
MajorTickLineStyle="{TemplateBinding MajorTickLineStyle}"
MinorTickLineStyle="{TemplateBinding MinorTickLineStyle}"
ap:Device.SnapsToDevicePixels="True">
<Image x:Name="PART_AxisBitmapImage"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Stretch="Fill"
ap:Device.SnapsToDevicePixels="True" />
<Grid x:Name="PART_LabelsCanvas" Margin="{Binding LabelToTickIndent, RelativeSource={RelativeSource FindAncestor, AncestorType=themes:AxisPanel}, Mode=OneWay}">
<themes:TickLabelAxisCanvas AutoFitMarginalLabels="{TemplateBinding AutoFitMarginalLabels}"
Background="Transparent"
ClipToBounds="False"
IsLabelCullingEnabled="{TemplateBinding IsLabelCullingEnabled}"
ap:Device.SnapsToDevicePixels="True" />
<themes:TickLabelAxisCanvas AutoFitMarginalLabels="{TemplateBinding AutoFitMarginalLabels}"
Background="Transparent"
ClipToBounds="False"
IsLabelCullingEnabled="{TemplateBinding IsLabelCullingEnabled}"
Visibility="Collapsed"
ap:Device.SnapsToDevicePixels="True" />
</Grid>
<labelProviders:AxisTitle Orientation="{TemplateBinding Orientation}"
Style="{TemplateBinding TitleStyle}"
Visibility="{Binding Content, RelativeSource={RelativeSource Self}, Converter={StaticResource CollapseIfNullOrEmptyStringConverter}}" />
</themes:AxisPanel>
<themes:ModifierAxisCanvas x:Name="PART_ModifierAxisCanvas"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ap:Device.SnapsToDevicePixels="True" />
</Grid>
<ContentPresenter Content="{TemplateBinding Scrollbar}" apc:AxisLayoutHelper.IsOutsideItem="True" />
</StackPanel>
</Border>
</ControlTemplate>
Here is the modified template (including converters)
<s:DateTimeAxis AxisAlignment="Bottom"
AxisTitle="Top Axis"
BorderThickness="0,0,0,1"
Id="TopAxisId">
<s:DateTimeAxis.Resources>
<s:AxisAlignmentToAxisOrientationConverter x:Key="AxisAlignmentToAxisOrientationConverter" />
<s:CollapseIfNullOrEmptyStringConverter x:Key="CollapseIfNullOrEmptyStringConverter" />
</s:DateTimeAxis.Resources>
<s:DateTimeAxis.Template>
<ControlTemplate TargetType="s:AxisBase">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
s:Device.SnapsToDevicePixels="True">
<StackPanel x:Name="PART_AxisContainer"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Orientation="{Binding AxisAlignment, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, Converter={StaticResource AxisAlignmentToAxisOrientationConverter}, ConverterParameter=Inverse}"
s:Device.SnapsToDevicePixels="True"
s:AxisLayoutHelper.AxisAlignment="{Binding AxisAlignment, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
<ContentPresenter Content="{TemplateBinding Scrollbar}" />
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Canvas.ZIndex="1"
s:Device.SnapsToDevicePixels="True"
>
<s:AxisPanel x:Name="PART_AxisCanvas"
AxisAlignment="{TemplateBinding AxisAlignment}"
Background="Transparent"
DrawLabels="{TemplateBinding DrawLabels}"
DrawMajorTicks="{TemplateBinding DrawMajorTicks}"
DrawMinorTicks="{TemplateBinding DrawMinorTicks}"
IsLabelCullingEnabled="{TemplateBinding IsLabelCullingEnabled}"
MajorTickLineStyle="{TemplateBinding MajorTickLineStyle}"
MinorTickLineStyle="{TemplateBinding MinorTickLineStyle}"
s:Device.SnapsToDevicePixels="True">
<Image x:Name="PART_AxisBitmapImage"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Stretch="Fill"
s:Device.SnapsToDevicePixels="True" />
<Grid x:Name="PART_LabelsCanvas" Margin="{Binding LabelToTickIndent, RelativeSource={RelativeSource FindAncestor, AncestorType=s:AxisPanel}, Mode=OneWay}">
<s:TickLabelAxisCanvas AutoFitMarginalLabels="{TemplateBinding AutoFitMarginalLabels}"
Background="Transparent"
ClipToBounds="False"
IsLabelCullingEnabled="{TemplateBinding IsLabelCullingEnabled}"
s:Device.SnapsToDevicePixels="True" />
<s:TickLabelAxisCanvas AutoFitMarginalLabels="{TemplateBinding AutoFitMarginalLabels}"
Background="Transparent"
ClipToBounds="False"
IsLabelCullingEnabled="{TemplateBinding IsLabelCullingEnabled}"
Visibility="Collapsed"
s:Device.SnapsToDevicePixels="True" />
</Grid>
<s:AxisTitle Orientation="{TemplateBinding Orientation}"
Style="{TemplateBinding TitleStyle}"
Visibility="{Binding Content, RelativeSource={RelativeSource Self}, Converter={StaticResource CollapseIfNullOrEmptyStringConverter}}" />
</s:AxisPanel>
<s:ModifierAxisCanvas x:Name="PART_ModifierAxisCanvas"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
s:Device.SnapsToDevicePixels="True" />
</Grid>
</StackPanel>
</Border>
</ControlTemplate>
</s:DateTimeAxis.Template>
<s:DateTimeAxis.Scrollbar>
<s:SciChartScrollbar Margin="0 3 0 0" />
</s:DateTimeAxis.Scrollbar>
</s:DateTimeAxis>
This code includes the default control template of the AxisBase in SciChart but removes two critical attached properties: AxisLayoutHelper.IsOutsideItem / IsInsideItem. These properties are used to adjust the order of Axis vs, Scrollbar depending on alignment of the axis. Removing them, you can place the ContentPresenter for the scrollbar anywhere and it will stay put.
This is tested as working in v4 of SciChart WPF
I like to create rounded corner for my video in Windows phone 8 app development.How to get this?
I have tried this below code
<Border x:Name="border" BorderThickness="1" BorderBrush="#FF000000" CornerRadius="20" Padding="1"
HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid>
<Border Name="mask" Background="Transparent" CornerRadius="{Binding ElementName=border, Path=CornerRadius}"/>
<Grid>
<Grid.OpacityMask>
<VideoBrush SourceName="{Binding ElementName=mask}"/>
</Grid.OpacityMask>
<MediaElement x:Name="Media" HorizontalAlignment="Left" Height="128"
VerticalAlignment="Top" Width="236" Source="/Assets/Videos/empty.m4v"/>
</Grid>
</Grid>
</Border>
I am developing an application and trying to achieve a sort of flip effect(like flipboard)
this is my xaml.
<Page.Resources>
<Storyboard x:Name="FlipBottomStoryboard">
<DoubleAnimation Duration="0:0:1.1" To="-80.9" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
</Storyboard>
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid Grid.RowSpan="2">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Rectangle Stroke="Black" Fill="#FF4E608F"/>
</Grid>
<Grid x:Name="grid" Grid.Row="2" Grid.RowSpan="2" Canvas.ZIndex="1">
<Grid.Projection>
<PlaneProjection CenterOfRotationX="0" CenterOfRotationY="0"/>
</Grid.Projection>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Tapped">
<Media:ControlStoryboardAction Storyboard="{StaticResource FlipBottomStoryboard}"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<Rectangle Fill="#FF3DDA24" Stroke="Black" Grid.Row="1"/>
</Grid>
<Rectangle Stroke="Black" Grid.Row="1" Grid.RowSpan="2">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FFA65757"/>
<GradientStop Color="#FF0A2E26" Offset="0.966"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
In short the grid on the lower half animates its RotationX when it is tapped.
The problem is that on the emulator(WVGA 4 inch 512mb) this works well but on the device (lumia 630 512mb) the animation jumps from the initial position to the end. Also the framerate drops to 30.
Any help is welcome on the matter
I've put a WebView inside of a FlipViewItem. The problem seems to be that in WP 8.1, the WebView does not get the gestures (presumably because they're absorbed by the FlipView). The desired result is to be able to scroll vertically and tap in the WebView but also to be able scroll horizontally for the FlipView (even if just in a limited area on the horizontal edges). Is there any solution or workaround for this?
<StackPanel>
<StackPanel Name="postTitle" Background="Transparent">
<TextBlock Name="ContentArea" Text="" FontSize="18" Margin="10, 5, 10, 0" TextWrapping="WrapWholeWords" FontWeight="Bold" Foreground="White"/>
<TextBlock Name="SubArea" Text="" FontSize="16" Margin="10, 0, 10, 10" TextWrapping="WrapWholeWords" Foreground="White"/>
</StackPanel>
<FlipView Name="swipeArea" Height="460" Margin="0" Padding="0" SelectedIndex="1" SelectionChanged="swipeArea_SelectionChanged">
<FlipViewItem Name="oneItem">
</FlipViewItem>
<FlipViewItem Name="mainFlipViewItem">
<Grid>
<ProgressRing Name="progRing" Foreground="White" Margin="0,25,0,0" Background="Transparent" Visibility="Collapsed" VerticalAlignment="Top"/>
<WebView Name="InterWindow" Height="460" Visibility="Collapsed" DefaultBackgroundColor="#5E5E5E"></WebView>
<ScrollViewer Name="Scrollster" ZoomMode="Enabled" MinZoomFactor="1" MaxZoomFactor="8" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Image Name="WebWindow" Height="420" HorizontalAlignment="Center" VerticalAlignment="Top">
</Image>
</ScrollViewer>
</Grid>
</FlipViewItem>
<FlipViewItem Name="threeItem">
</FlipViewItem>
</FlipView>
</StackPanel>
I believe I just found one workaround. I've added this to the WebView control:
Canvas.ZIndex="1000"
I can then set the width of the WebView control to something just slimmer than the FlipView itself, and then I should be good.
Im having Listview which shows 185 columns and 15 rows. For showing 185 columns with 15 rows, windows store app takes some time or UI gets freezes. below is the code Im using for showing data
<ListView x:Name="outerlstView"
Height="650"
Margin="2,24,10,10" Grid.Row="1"
Grid.Column="1" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource="{Binding Data,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectionMode="None" ShowsScrollingPlaceholders="True" IsZoomedInView="False"
IsSwipeEnabled="False" IsItemClickEnabled="False"
ItemContainerStyle="{StaticResource LvItemStyle}"
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
Orientation="Vertical" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<ListView SelectionMode="None" IsZoomedInView="False" IsHoldingEnabled="False"
IsSwipeEnabled="False" x:Name="ListRow" ItemsSource="{Binding data, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" Width="Auto" Height="Auto"
VerticalAlignment="Center" ItemContainerStyle="{StaticResource LvItemStyle}" AllowDrop="True"
ShowsScrollingPlaceholders="True">
<interactivity:Interaction.Behaviors>
<awbehaviors:DragBehaviour/>
</interactivity:Interaction.Behaviors>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="35" Width="120" HorizontalAlignment="Center" >
<Rectangle StrokeDashArray="1 1 0.3 1" Height="30" VerticalAlignment="Top" IsHitTestVisible="False" Opacity="0.5" Stroke="White" StrokeThickness="1" Margin="0" StrokeEndLineCap="Square" StrokeDashOffset="1.5"
Fill="{Binding ElementName=ListRow,Path=Tag,Converter={StaticResource RowNotoBackgroundConverter}}"/>
<TextBlock Text="{Binding FeedCellData,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left"
tyle="{StaticResource GridItemTextStyle}" Width="120" AllowDrop="True" Padding="1" TextWrapping="NoWrap"
VerticalAlignment="Top" Tag="{Binding ElementName=ListRow,Path=Tag}" ToolTipService.ToolTip="{Binding FeedCellData}"
Height="{Binding Path=Tag, RelativeSource={RelativeSource Mode=Self},Converter={StaticResource RowtoHeightConverter }}" >
</TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Margin="0,0,0,0" Width="Auto" Orientation="Horizontal" Height="35" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
the above code has listview inside it another listview. when i try to load list<list> to listview it takes too much of time. Some time app crashes when i load 100 rows with 185 columns.
I tried to replace Itemtemplate stye control to Itemstackpanel performance is good. data is loaded and shown on screen faster but i dont see Horizontal scroll
Previous Code
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
Orientation="Vertical" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
when i modify to `<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Margin="0,0,0,0" Width="Auto" Orientation="Horizontal" Height="35" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>`
i dont see horizontal scrollbar enabled. Can any1 suggest me how to enable Horizontal scroll bar enabled by default to Itemstackpanel in windows store apps.Looks like it is bug with this control or there work arounds to ItemsStackpanel with Horizontal Scrollbar.
If your ItensSource is a list of objects with a attribute Name and a attribute Price for example:
<ListView ItemsSource="{Binding Here_your_DataSource}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="15"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<!--Here u design your item template-->
<StackPanel Background="Blue" Width="100" Height="100">
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock Text="{Binding Price}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>