i want to play video in my app. I see around but nothing helped me. I ask the user if he wants to listen to his phone music. If clicks ok the music continue playing, if not then the music stop. That is ok from now. Now, my problem is: I create a grid to use it like popup with width and height and so on.. When this popup appears the music stops. This is why can not certify my app in marketplace.
Here is a little code: i believe is easy to understand... Please help!
public void new_grid(int v)
{
Grid gr = new Grid();
gr.Background = new SolidColorBrush(Colors.Cyan);
gr.Opacity = 1.0;
gr.Width = 400;
gr.Height = 600;
// Create a white border.
Border border = new Border();
border.BorderBrush = new SolidColorBrush(Colors.White);
border.BorderThickness = new Thickness(7.0);
MediaElement video_ship = new MediaElement();
//video_ship.AutoPlay = false;
video_ship.Width = 400;
video_ship.Height = 600;
video_ship.VerticalAlignment = VerticalAlignment.Top;
video_ship.HorizontalAlignment = HorizontalAlignment.Left;
if (v == 1)
{
video_ship.Source = new Uri("videos/Lost_Ship.wmv", UriKind.RelativeOrAbsolute);
//video_ship.Play();
gr.Children.Add(video_ship);
}
else if (v == 2)
{
//video_ship.Source = "videos/Lost_Ship.wmv";
video_ship.Source = new Uri("videos/you_are_on_fire.wmv", UriKind.RelativeOrAbsolute);
//video_ship.Name = "fire";
//video_ship.Play();
gr.Children.Add(video_ship);
}
else if (v == 3)
{
//video_ship.SourceName = "videos/Lost_Ship.wmv";
video_ship.Source = new Uri("videos/EscapeShip.wmv", UriKind.RelativeOrAbsolute);
//video_ship.Name = "escape";
//video_ship.Play();
gr.Children.Add(video_ship);
}
I send a variable v to select one of my videos..I set the videos to Build Action Content
Any ideas what to do? or something different than this?
I want only to play the video ..Video does not have music ..or sound effect..
I tested it and it works. You want to popup video when you call event. so you shoud put grid inside file xaml code and it is hidden.
This is my test
on xaml
<Grid x:Name="LayoutRoot" Background="Transparent">
<Image Source="BackgroundMain3.jpg" Stretch="UniformToFill"/>
<Grid Height="400" Width="600" x:Name="playvideo" Visibility="Collapsed">
<MediaElement x:Name="element"/>
</Grid>
<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="129,684,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
</Grid>
on xaml.cs
private void button1_Click(object sender, RoutedEventArgs e)
{
poupup(3);
playvideo.Visibility = Visibility.Visible;
playvideo.Opacity = 0.8;
element.MediaOpened += new RoutedEventHandler(element_MediaOpened);
}
void element_MediaOpened(object sender, RoutedEventArgs e)
{
element.Play();
}
public void poupup(int v)
{
if (v == 1)
{
element.Source = new Uri("videos/Lost_Ship.wmv", UriKind.RelativeOrAbsolute);
}
else if (v == 2)
{
element.Source = new Uri("videos/you_are_on_fire.wmv", UriKind.RelativeOrAbsolute);
}
else if (v == 3)
{
element.Source = new Uri("YouTube.mp4", UriKind.RelativeOrAbsolute);
}
}
Related
I have a xamarin.forms app which uses Rg.Plugins.Popup. I have a list view with an "edit" icon on each view cell. I am opening the popup when we click on this icon. The problem is the popup will open at the center of screen no matter what where the listview cells position. How can we open the popup exactly at the position of listview cell which being clicked? Is it possible? Any help is appreciated.
For now, Rg.Plugins.Popup support the Animations for Right, Left, Center, Top, Bottom.
For more details of Animations, you could check the link below. https://github.com/rotorgames/Rg.Plugins.Popup/wiki/Animations#custom-animations
Applying a custom animations in a xaml file:
class UserAnimation : MoveAnimation
{
private double _defaultTranslationY;
public UserAnimation()
{
DurationIn = DurationOut = 300;
EasingIn = Easing.SinOut;
EasingOut = Easing.SinIn;
PositionIn = MoveAnimationOptions.Right;
PositionOut = MoveAnimationOptions.Right;
}
public override void Preparing(View content, PopupPage page)
{
base.Preparing(content, page);
page.IsVisible = false;
if (content == null) return;
_defaultTranslationY = content.TranslationY;
}
public override void Disposing(View content, PopupPage page)
{
base.Disposing(content, page);
page.IsVisible = true;
if (content == null) return;
content.TranslationY = _defaultTranslationY;
}
public async override Task Appearing(View content, PopupPage page)
{
var taskList = new List<Task>();
taskList.Add(base.Appearing(content, page));
if (content != null)
{
var topOffset = GetTopOffset(content, page);
var leftOffset = GetLeftOffset(content, page);
taskList.Add(content.TranslateTo(content.Width, _defaultTranslationY, DurationIn, EasingIn));
};
page.IsVisible = true;
await Task.WhenAll(taskList);
}
public async override Task Disappearing(View content, PopupPage page)
{
var taskList = new List<Task>();
taskList.Add(base.Disappearing(content, page));
if (content != null)
{
_defaultTranslationY = content.TranslationX - content.Width;
var topOffset = GetTopOffset(content, page);
var leftOffset = GetLeftOffset(content, page);
taskList.Add(content.TranslateTo(leftOffset, _defaultTranslationY, DurationOut, EasingOut));
};
await Task.WhenAll(taskList);
}
}
Usage:
<pages:PopupPage.Animation>
<animations:UserAnimation />
</pages:PopupPage.Animation>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Frame BackgroundColor="Silver">
<StackLayout Spacing="20">
<Label
FontSize="16"
HorizontalOptions="Center"
Text="User Animation" />
<Button Clicked="OnClose" Text="Close" />
</StackLayout>
</Frame>
</StackLayout>
OnClose event:
private void OnClose(object sender, EventArgs e)
{
PopupNavigation.Instance.PopAsync();
}
If you wannna Left, Top, Botton, Center for the Popup, you could change the MoveAnimationOptions of your custom animations.
PositionIn = MoveAnimationOptions.Right;
PositionOut = MoveAnimationOptions.Right;
i want to create a greeting card maker app for WP7, when a user double taps an image from a listbox, I want that selected image to fill a rectangle on the same page.
Im passing 50 images into the list box like this:
public GCM()
{
InitializeComponent();
var articles = new List<Article>();
for (byte i = 1; i <= 20; i++)
{
Article article = new Article() { Name = "name"+i, ImagePath = "Assets/Images/Backgrounds/"+i+".jpg" };
articles.Add(article);
}
listBox1.DataContext = articles;
}
and its working fine, now heres an xml snippet:
<Rectangle Fill="#FFF4F4F5" Margin="28,24,30,148" Stroke="Black" Name="rect1" />
................(more code here).........................
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="10" >
<Image Name="bgs" Source="{Binding ImagePath}" Height="90" Width="90" DoubleTap="Load_BG" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
how can i fill the rectangle with the tapped image? this code (below) sets the string null everytime, no matter which image i select, although to my knowledge each has a different name and it should give different names for different images. I will use the name of the image to fill the rectangle. What am i doing wrong?
private void Load_BG(object sender, System.Windows.Input.GestureEventArgs e)
{
string abc = sender.GetType().Name;
}
Please excuse me if the solution is obvious..this is my first app ever. Thank you!
sender parameter should contains the control that triggered the event, in this case Image control. Try to cast it to Image type, then you can get the information you needed from Source property :
private void Load_BG(object sender, System.Windows.Input.GestureEventArgs e)
{
Image img = (Image)sender;
//do something with img.Source here
}
so heres the solution, it works now :)
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var img = listBox1.SelectedItem as Article;
ImageBrush imgBrush = new ImageBrush();
imgBrush.ImageSource = new BitmapImage(new Uri(img.ImagePath, UriKind.RelativeOrAbsolute));
rect1.Fill = imgBrush;
}
I need an image that can follow my finger (mouse) on the screen... the following code works fine on Portrait Mode, but it get's completely mess up on Landscape Mode, has anybody been across to this?
<Image Height="68" HorizontalAlignment="Left" Margin="872,388,0,0" Name="imgStarPoint" Stretch="Fill" VerticalAlignment="Top" Width="54" Source="/GetMousePoint;component/StarT.png" ManipulationCompleted="imgStarPoint_ManipulationCompleted">
<i:Interaction.Behaviors>
<el:MouseDragElementBehavior x:Name="imgStar"/>
</i:Interaction.Behaviors>
</Image>
and code behind:
void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
var PrimaryPoint = e.GetPrimaryTouchPoint(null);
imgStar.X = PrimaryPoint.Position.X;
imgStar.Y = PrimaryPoint.Position.Y;
txt1.Text = PrimaryPoint.Position.X + "." + PrimaryPoint.Position.Y;
}
Does anybody has a way to set the image on my finger tip on Landscape Mode?
EDIT:
Ok, for some reason I though you were using WP Toolkit's Gesture listener which will report the correct X any Y in each orientation mode. In your case you need to detect which orientation mode you are in and do the necessary adjustments.
It seems like when orientation is in landscape the axis are switched. When in landscape-left mode the X axis is inverted and in landscape-right mode the Y axis is inverted. Following code should fix your problem:
bool _switchAxis;
bool _invertX ;
bool _invertY;
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) {
_switchAxis = (e.Orientation | PageOrientation.LandscapeLeft | PageOrientation.LandscapeRight) == (PageOrientation.LandscapeLeft | PageOrientation.LandscapeRight);
_invertX = e.Orientation == PageOrientation.LandscapeLeft;
_invertY = e.Orientation == PageOrientation.LandscapeRight;
}
private void Touch_FrameReported(object sender, System.Windows.Input.TouchFrameEventArgs e) {
var width = Application.Current.Host.Content.ActualWidth;
var height = Application.Current.Host.Content.ActualHeight;
var primaryPoint = e.GetPrimaryTouchPoint(null);
if (_switchAxis) {
if (_invertY) imgStar.X = height - primaryPoint.Position.Y; else imgStar.X = primaryPoint.Position.Y;
if (_invertX) imgStar.Y = width - primaryPoint.Position.X; else imgStar.Y = primaryPoint.Position.X;
} else {
imgStar.X = primaryPoint.Position.X;
imgStar.Y = primaryPoint.Position.Y;
}
}
You need to add OrientationChanged event to your page xaml:
<phone:PhoneApplicationPage
<!-- ... -->
OrientationChanged="PhoneApplicationPage_OrientationChanged"
/>
In Landscape mode, a visible application bar and system tray will mess up X for you.
If you have an application bar, set its mode to minimized
ApplicationBar.Mode = ApplicationBarMode.Minimized
You also need to hide the system tray to avoid manual adjustments on X. Do that on the page Loaded event
Xaml:
<phone:PhoneApplicationPage
<!-- stuff -->
Loaded="PhoneApplicationPage_Loaded"
/>
Code behind:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) {
SystemTray.IsVisible = false;
}
Also you would want to deduct image.Width/2 from X and image.Height/2 from Y to make it exactly at the center of your finger tip.
imgStar.X = PrimaryPoint.Position.X - (img.Width/2);
imgStar.Y = PrimaryPoint.Position.Y - (img.Height/2);
That should fix the problem.
In my app I have several pages. When I click on the Windows "Back" Button everything goes back as expected.
However I have 2 pages that are causing me grief. Page "A" is doing some binding in the XAML:
<ListBox x:Name="lbPrograms" ItemsSource="{Binding Items}" SelectionChanged="lbPrograms_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
<Image x:Name="ItemImage" Source="/images/ArrowImg.png" Height="43" Width="43" VerticalAlignment="Top" Margin="10,0,20,0"/>
<StackPanel>
<TextBlock x:Name="ItemText" Text="{Binding programName}" Margin="-2,-13,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock x:Name="DetailsText" Text="{Binding createDate}" Margin="0,-6,0,3" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
<Image x:Name="ItemFavs" Source="/images/favs.png" Height="43" Width="43" VerticalAlignment="Top" Margin="10,0,20,0"/>
<Image x:Name="ItemDelete" Source="/images/delete.png" Height="43" Width="43" VerticalAlignment="Top" Margin="10,0,20,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The code behind for Page A is fairly simple:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
// Set the data context of the listbox control to the sample data
if (DataContext == null)
DataContext = App.ViewModel;
App.ViewModel.Refresh();
lbPrograms.ItemsSource = App.ViewModel.Items;
}
private void lbPrograms_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(new Uri("/DisplayProgram.xaml?selectedItem=" + lbPrograms.SelectedIndex, UriKind.Relative));
}
private void BackBtn_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
Page B has no binding in the XAML as I am taking the data from the ModelView a drawing it out dynamically on the screen. Like so:
private int index;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
//prevents error
if (int.Parse(selectedIndex) == -1)
{
return;
}
if ((DataContext == null))
{
index = int.Parse(selectedIndex);
App.ViewModel.Refresh();
DataContext = App.ViewModel.Items[index].nValDictionary;
int i = 0;
foreach (KeyValuePair<string, string> kvp in (((System.Collections.Generic.Dictionary<string, string>)(DataContext))))
{
StackPanel sp = new StackPanel();
sp.Name = "sp" + i;
sp.Background = new SolidColorBrush(Colors.Black);
sp.Width = 460;
WrapPanel wp = new WrapPanel();
wp.Name = "test" + i;
wp.Width = 300;
wp.Height = 200;
TextBlock txt = new TextBlock();
txt.Text = kvp.Key.ToString();
txt.Foreground = new SolidColorBrush(Colors.White);
sp.Children.Add(txt);
int chkBoxesVal = 0;
if (kvp.Value == "")
{
chkBoxesVal = 0;
}else{
chkBoxesVal = Convert.ToInt32(kvp.Value.ToString());
}
int iCount = 0;
for (iCount = 0; iCount <= chkBoxesVal - 1; iCount++)
{
CheckBox chk = new CheckBox();
chk.Name = i.ToString();
chk.Width = 56;
chk.Height = 70;
chk.Content = "";
//chk.Background = new SolidColorBrush(Colors.Black);
//chk.BorderBrush = new SolidColorBrush(Colors.White);
chk.Style = (Style)Application.Current.Resources["checkBoxNG"];
wp.Children.Add(chk);
}
sp.Children.Add(wp);
lbItems.Items.Add(sp);
i += 1;
}
}
}
}
}
So when I'm going forward everything works fine, but when I hit the Windows "Back" button on Page B I get an error. I stepped through my code and when I hit the "Back" button it does go back to Page A, but then it is also going to Page B, which then throws the error and stops. So can anyone tell me why this behavior is happening? I would expect that it would go back to Page A and just stop there. Not to go back to Page B. is there something in my code that is causing it to reload Page B? Any resources that you can provide that might explain this behavior is also welcome!
Thanks!
It looks like SelectionChanged on Page A is firing as a result of the ItemsSource initialisation you're doing in OnNavigatedTo.
You could verify the SelectedIndex is -1 before taking any action in the SelectionChanged event.
Alternatively you could remove any existing event handler on SelectionChanged while doing this initialisation and restore that event handler on completion.
My assumption is that lbPrograms_SelectionChanged event occurs when you press back button and page A is loaded again.
Change your navigation design. For your DataTemplateStackPanel you could use ManipulationStarted event
and inside add
NavigationService.Navigate(new Uri("/DisplayProgram.xaml?selectedItem=" + lbPrograms.SelectedIndex, UriKind.Relative));
I Want to Display the Images Dynamically.i'e If Whenever Click On Particular image some more (4 to 5 times)times that can be disappear and new image can be fill this place.in that i want to display the images dynamically in windows phone 7 using silverlight.
I know this is a very old question but I had a couple of free minutes ;)
The following will display a different random image from the images stored on the device every fourth time the screen is tapped.
XAML:
xmlns:Controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Background>
<ImageBrush x:Name="myImg" />
</Grid.Background>
<Controls:GestureService.GestureListener>
<Controls:GestureListener Tap="GestureListener_Tap" />
</Controls:GestureService.GestureListener>
</Grid>
C#
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using Microsoft.Xna.Framework.Media;
private int tapCount = 0;
private void GestureListener_Tap(object sender, GestureEventArgs e)
{
tapCount += 1;
if (tapCount % 4 == 0)
{
SetRandomImage();
}
}
private void SetRandomImage()
{
var lib = new MediaLibrary();
using (var pic = lib.Pictures[new Random().Next(0, lib.Pictures.Count - 1)])
{
var img = new BitmapImage();
img.SetSource(pic.GetImage());
myImg.ImageSource = img;
}
}