How to implement a 'AddToFavorites' button on an win8 app - xaml

I am developing an app on win8 and would like to add an 'AddToFavorites' button on the application bar, so that the user can select his favorites/bookmarks and place them to this. I have added this button to the application bar but the button does not perform any action when clicked.
Currently what I have done is
private async void Favorite_Button_Click(object sender, RoutedEventArgs e)
{
if (SampleDataSource.GetGroup("Favorite").Items.Count != 0)
{
if (this.pageTitle.Text != "Favorite")
this.Frame.Navigate(typeof(ItemDetailPage), SampleDataSource.GetGroup("Favorite").Items[0].UniqueId);
}
else
{
await new Windows.UI.Popups.MessageDialog("You haven't marked any favorites.").ShowAsync();
}
}
But I dont see this functionality working. Any of your suggestions would be of great help to me. It is a Windows8 Metro style C#/XAML App.
Thanks in Advance!

Related

How to animate SettingsFlyout on dismiss

In Windows 8.1, I'm using the new SettingsFlyout control. The flyout animates in correctly and will animate out if you use the control's built-in back button to return to the Settings Charm flyout. But if you light dismiss by clicking outside the flyout, it disappears without a transition animation.
How do you animate a transition out when you light dismiss the SettingsFlyout? (I don't want to return to the Settings Charm flyout, I just want it to slide out on a light dismiss.)
Matt, what you want to do should be easily achievable but is currently not supported by the XAML SettingsFlyout API out of the box. As Jerry points out, there are transitions that allow an animate out effect (in XAML you want EdgeUIThemeTransition). Unfortunately, there is no API support on SettingsFlyout to add this transition, but you can get it to work using your own private popup to host the SettingsFlyout (more on this below):
public sealed partial class SettingsFlyout1 : SettingsFlyout
{
Popup _p;
Border _b;
public SettingsFlyout1()
{
this.InitializeComponent();
BackClick += SettingsFlyout1_BackClick;
Unloaded += SettingsFlyout1_Unloaded;
Tapped += SettingsFlyout1_Tapped;
}
void SettingsFlyout1_BackClick(object sender, BackClickEventArgs e)
{
_b.Child = null;
SettingsPane.Show();
}
void SettingsFlyout1_Unloaded(object sender, RoutedEventArgs e)
{
if (_p != null)
{
_p.IsOpen = false;
}
}
void SettingsFlyout1_Tapped(object sender, TappedRoutedEventArgs e)
{
e.Handled = true;
}
public void ShowCustom()
{
_p = new Popup();
_b = new Border();
_b.ChildTransitions = new TransitionCollection();
// TODO: if you support right-to-left builds, make sure to test all combinations of RTL operating
// system build (charms on left) and RTL flow direction for XAML app. EdgeTransitionLocation.Left
// may need to be used for RTL (and HorizontalAlignment.Left on the SettingsFlyout below).
_b.ChildTransitions.Add(new EdgeUIThemeTransition() { Edge = EdgeTransitionLocation.Right });
_b.Background = new SolidColorBrush(Colors.Transparent);
_b.Width = Window.Current.Bounds.Width;
_b.Height = Window.Current.Bounds.Height;
_b.Tapped += b_Tapped;
this.HorizontalAlignment = HorizontalAlignment.Right;
_b.Child = this;
_p.Child = _b;
_p.IsOpen = true;
}
void b_Tapped(object sender, TappedRoutedEventArgs e)
{
Border b = (Border)sender;
b.Child = null;
}
}
Full solution for this sample: https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/SettingsFlyout_AnimateOut
I think SettingsFlyout should have API support for your scenario, so I filed a work item on the XAML team. In the future, such requests/issues can be raised on the MSDN forum as well (moderated by MSFT folks). The limitation here is that SettingsFlyout is implemented on top of Popup with IsLightDismissEnabled="True", and the light-dismiss event currently closes the Popup immediately without allowing unloading child transitions to run. I think this can be overcome and transitions can be supported at the SettingsFlyout API level to enable your scenario.
You need to use the HideEdgeUI animation
Read this: http://msdn.microsoft.com/en-us/library/windows/apps/jj655412.aspx

Stop YouTube Video on Back Button of Windows Metro App 8.1

I have a page on which i am showing multiple youtube videos as webviews. When i play any video, then correspoding video starts playing. But When I click on the back button of the App i should be stop then but its running in background(can hear voice of video).
here is the code of back button:
protected void GoBack(object sender, RoutedEventArgs e)
{
((Frame)Window.Current.Content).GoBack();
}
Tell me how i can dispose of this webview or can stop video.
Thanks
First make sure that the page is finalized; most probably by detaching all the event handlers you manually attached before. Then (sooner or later) the page will be finalized which in turns disposes of the webview.
A similar effect would be achieved by forward navigating the webview to an empty html page.
Here is the solution:
Invoke the UnLoaded event of WebView
- webView.Unloaded += webView_UnLoaded;
Then change the source of the webview in webView_UnLoaded event handler:
Here is my code:
private void webView_UnLoaded(object sender, RoutedEventArgs e)
{
WebView webView = (WebView)sender;
webView.Source = new Uri(" ");
}

Hide virtual keyboard in windows 8 metro

Now i am working on Windows 8 Metro application. For that i have a popup window with textbox and OK button. I need to hide Virtual Keyboard when "Enter" is clicked on Virtual keyboard. If i click "OK" button on popup keyboard hides automatically.
I got this Link as good reference (using HiddenField). Is there any way to done this work without using "HiddenField". Thanks in advance..
Well finally found a solution for this issue.. I just change the focus from textbox to button in my popup.. below is the sample code..
public void FocusTextbox(object sender, EventArgs e)
{
// set focus to textbox on popup open
Textbox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
public void Textbox_KeyDown(object sender, KeyRoutedEventArgs e)
{
// conforming the "Enter" button click
if (e.Key == Windows.System.VirtualKey.Enter)
{
// change the focus to OK button
this.OkButton.Focus(Windows.UI.Xaml.FocusState.Pointer);
}
}
Change the focus before closing the popup... it works great now..
And changing the focus to Label or Textblock is not hiding the Virtual keyboard...
i was also looking for this , but i found this approach first

Close Telerik radgridview custom Filter Control

i am using telerik silverlight lib. Version = 2011.1.411.1040
i am create one custom filter control for telerik silverlight RadGridView,
in this control one close button at right hand top corner
i want to close filter control on click of close button, how can i achieve this
after spend very long time for resolve this issue. i hope bellow code can help you, it was help me so
private void btnclose_Click(object sender, RoutedEventArgs e)
{
FilteringDropDown down = Telerik.Windows.Controls.UIElementExtensions.ParentOfType<FilteringDropDown>(this);
if (down != null)
{
down.IsDropDownOpen = false;
}
}

Force a view to refresh?

I'm trying to do a loading icon where once you tap on the icon, it will call the following handler:
private void refresh_btn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
refresh_btn.Visibility = System.Windows.Visibility.Collapsed;
loading_icon.Visibility = System.Windows.Visibility.Visible;
refreshMix();
}
private void refreshMix()
{
...
refresh_btn.Visibility = System.Windows.Visibility.Collapsed;
loading_icon.Visibility = System.Windows.Visibility.Visible;
}
However, the view doesn't seem to auto-reload after I change the icon visibilities before calling refreshMix(). Is there a way to force the page to reload itself?
You are probably doing some lengthy work in refreshMix() in UI thread, right? Do this work in background thread and UI thread will be free to update page.
You need set Collapsed before Visible :
control.Visibility = System.Windows.Visibility.Collapsed;
control.Visibility = System.Windows.Visibility.Visible;
Within Silverlight there is no concept of page or view re-loading. When you change the properties of any visual element, this will be reflected on the screen the next time it is rendered.