i have a pivot page with 3 pages and there are two application bar buttons. But i want that when pivot is changed, the first button of application bar should do different tasks on different pivot, and second button will do same task on all pivots. I am doing this as:
private void PivotControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ApplicationBarIconButton firstButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
if (PivotControl.SelectedIndex == 0)
{
firstButton.IsEnabled = true;
firstButton.Click += new EventHandler(FirstPivotButton_Click);
}
else if (PivotControl.SelectedIndex == 1)
{
firstButton.IsEnabled = true;
firstButton.Click += new EventHandler(SecondPivotButton_Click);
}
else if (PivotControl.SelectedIndex == 2)
{
firstButton.IsEnabled = false;
}
}
void FirstPivotButton_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/PageA.xaml", UriKind.Relative));
}
void SecondPivotButton_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/PageB.xaml", UriKind.Relative));
}
But the problem is that PageA is being navigated well but there is problem in going to PageB from secondpivotbutton click event. Please help me
Use this great library for simplifying usage of ApplicationBar on Windows Phone - AppBarUtils.
You can find them on NuGet as well.
There is also nice tutorial, how ti display different buttons for each panorama/pivot item using this library:
http://allenlooplee.wordpress.com/2012/09/17/how-to-show-different-app-bar-for-different-pivotpano-item/
Here's how I did this in one of my apps. Button 1 is different for pivot pages and button 2 is always the same, just like you.
On the SelectionChanged event, update the button icon uri and text:
Private Sub statPivot_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles statPivot.SelectionChanged
Dim saveBtn As ApplicationBarIconButton = ApplicationBar.Buttons(0)
If statPivot.SelectedIndex = 0 Then
'calculation pane active
saveBtn.Text = "save"
saveBtn.IconUri = New Uri("/Assets/AppBar/appbar.save.rest.png", UriKind.Relative)
Else
'history pane active
saveBtn.Text = "clear"
saveBtn.IconUri = New Uri("/Assets/AppBar/appbar.refresh.rest.png", UriKind.Relative)
End If
End Sub
then in the onclick event I detect the pivot pane that's being viewed and use a basic if...then...else... to run the different code within the same handler.
If you want dynamically change app bar buttons at run time you can do this:
<phone:PhoneApplicationPage.Resources>
<shell:ApplicationBar x:Key="appbar1" IsVisible="True">
<shell:ApplicationBarIconButton x:Name="abMain1" IconUri="/icons/appbar.favs.addto.rest.png" Text="blabla1"/>
</shell:ApplicationBar>
<shell:ApplicationBar x:Key="appbar2" IsVisible="True">
<shell:ApplicationBarIconButton x:Name="abMain2" IconUri="/icons/appbar.favs.addto.rest.png" Text="blabla2"/>
<shell:ApplicationBarIconButton x:Name="abMain3" IconUri="/icons/appbar.cancel.rest.png" Text="blabla3"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.Resources>
And then change it from code:
ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar) Resources["appbar1"];
and
ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar) Resources["appbar2"];
You can big numbers of different AppBars.
Hope its help.
Related
I'm trying to go to another page when clicking a button. How could i do this.
I tried using a NavigationViewItem but it didn't work.
The NavigationViewItem you posted is used in UWP.
If it is a WinUI3 project, then you need to refer to this document, use Navigate.
the relevant code samples are as follows.
xaml
<Button x:Name="myButton" Click="myButton_Click"/>
xaml.cs
private void myButton_Click(object sender, RoutedEventArgs e)
{
Frame rootFrame = new Frame();
this.Content = rootFrame;
rootFrame.Navigate(typeof(BlankPage1), null);
}
I have a pair of ComboBox controls having IsEditable() true as well as false.
When I am scrolling through my application or moving my application window (by clicking on the title bar) with list popup open, I would like to close the ComboBox list popup as otherwise there would be a weird delay in aligning the list correctly below the control.
Is this possible in UWP with WinRT/C++? If so, kindly suggest how to.
I did an investigation to find if any events are there to handle in such a scenario when ComboBox control is essentially displaced from initial position while moving the app window/scrolling the app, but couldn't find any help.
Edit: Adding ComboBox image from XAML Controls Gallery to demonstrate the behaviour. In case if IsEditable set as true, when popup is opened and application is scrolled then popup goes outside the window. Instead I would like to dismiss the popup itself. However, if IsEditable is set as false then we cannot scroll until the popup is dismissed.
Update: The code I tested for PointerWheelChanged
void CBFile2022X::OnPointerWheelChangedHandler( Windows::Foundation::IInspectable const& sender,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const& eventargs )
{
OutputDebugString( L"PointerWheelChanged" );
if( ComboBox != nullptr )
{
ComboBox.IsEnabled( false );
ComboBox.IsEnabled( true );
}
}
I have to say that currently there is no event to detect if the application window is moved or changed its location.
Update:
You could handle the UIElement.PointerWheelChanged Event which will be fired when users scroll the mouse wheel. You could set the IsEnabled property of the ComboBox to false first and then set it to true, this will make the ComboBox lose its focus. Like:
private void Mypanel_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
FontsCombo.IsEnabled = false;
FontsCombo.IsEnabled = true;
}
Update2:
If you are using a ScrollViewer you could try to handle the ScrollViewer.ViewChanging Event.
private void ScrollViewer_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e)
{
FontsCombo.IsEnabled = false;
FontsCombo.IsEnabled = true;
}
I want to add a button to the pivot header so that it is shown in-line with pivot item titles, but doesn't update the content shown but just launches an event instead.
After some experimenting, I discovered how to do this. First place a button inside a PivotItem's header. Set it up to route tap events as well as click events.
<PivotItem>
<PivotItem.Header>
<Button
x:Name="MyButton"
Tapped="PivotItem_Tapped"
Click="MyButton_Click">MyButton</Button>
</PivotItem.Header>
</PivotItem>
Then inside the handler for the tap, consume the tap event. Clicking on the button won't update the pivot's content now:
private void MyButton_Click(object sender, RoutedEventArgs e)
{
//do whatever you need.
}
private void PivotItem_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
e.Handled = true;
}
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
I have the following XAML code
XAML:
<Button x:Name = "Btn1" Click = "Button_Click">
can i change the color of the font in the Button_Click method or anywhere else in code?
You can implement it by the following code runs in directX 2013:
void App2::DirectXPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) {
bt->Foreground = ref new SolidColorBrush(Windows::UI::Colors::Blue);
}
Yes you can change the color of the button any where in the code
Here's a sample button and a sample code to change color in it's click event
Heres the code to change the color in the click event of the btnChangeFontColor
private void Button_Click_1(object sender, RoutedEventArgs e)
{
btnChangeFontColor.Foreground = new SolidColorBrush(Colors.Red);
}