I want to bind an AppBarButtons into a CommandBar.
I tried looking through the CommandBar documentation and found out that part is PrimaryCommands but I try to bind it but it read-only and I can't write anything to it.
Here is what I wanted to do.
<CommandBar PrimaryCommands={x:Bind AdditionCommands}/>
So, later on, I could just:
<customUI:PauseMenu>
<customUI:PauseMenu.AdditionCommands>
<AppBarButton Label="Some"/>
<AppBarButton Label="Commands"/>
<AppBarButton Label="Heres"/>
</customUI:PauseMenu.AdditionCommands>
</customUI:PauseMenu>
Can I bind AppBarButtons into CommandBar.PrimaryCommands
CommandBar does not support bind PrimaryCommands like the above. The only implementation way of PrimaryCommands is create list AppBarButton under that node. Please refer this document.
<CommandBar.PrimaryCommands>
<AppBarButton Label="Some"/>
<AppBarButton Label="Commands"/>
<AppBarButton Label="Heres"/>
</CommandBar.PrimaryCommands>
Related
I am trying to use NavigationView with custom icons as Menu Items in my UWP app. However, it seems NavigationView don't accept custom icons or BitmapIcon. The sample application I have seen in android is below;
Sample Code of NavigationView Menu Items
<NavigationView.MenuItems>
<NavigationViewItem Name="SalahNavItem" Icon="CustomIcon" Content="Apps" Tag="Salah"/>
<NavigationViewItem Name="AppsNavItem" Icon="CustomIcon1" Content="Apps" Tag="apps"/>
</NavigationView.MenuItems>
What I am trying to achieve is to add custom Icon / Image in Menu Items, any clue about it in UWP?
You can add custom Icon Use
<NavigationView.MenuItems>
<NavigationViewItem Name="SalahNavItem" Icon="CustomIcon" Content="Apps" Tag="Salah">
<NavigationViewItem.Icon>
<!-- Use Custom icon <FontIcon Glyph=""/>
Or <BitmapIco UriSource="Path"/> -->
</NavigationViewItem.Icon>
<NavigationViewItem Name="AppsNavItem" Icon="CustomIcon1" Content="Apps" Tag="apps"/>
</NavigationView.MenuItems>
See this link
Expanding a bit on the above answer:
<BitmapIcon UriSource="ms-appx:///Assets/globe.png"/>
https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.bitmapicon?view=winrt-22000
On this page in Windows Dev Center it says
The new dynamic overflow behavior will automatically move primary commands into the SecondaryCommands area when space is limited.
But in my App there are only 4 Buttons Visible, the 5th one is not there, also not if I open the Menu, I have to put it manually into the SecondaryCommands List, to make Windows showing it.
I made a plain simple CommandBar to test it
<CommandBar>
<AppBarButton Icon="Find" Label="test" />
<AppBarButton Icon="Find" Label="test" />
<AppBarButton Icon="Find" Label="test" />
<AppBarButton Icon="Find" Label="test" />
<AppBarButton Icon="Find" Label="test" />
</CommandBar>
Build Target and Min Version is 10.0 10586.
Also I noticed that CommandBarOverflowButtonVisibility and similar properties can't be found.
This is a feature that won't appear until the Anniversary Update--the documentation has just been updated too early. You can see the feature get explained in detail in this video from //BUILD 2016 at about 11:35. It is not currently available in Build 10586.
I'm just starting to learn C# and WP platform and i find it really hard to do some easy things, like changing a button icon, etc.
I've got a Command Bar and a AppBarButton created in XAML.
<Page.BottomAppBar>
<CommandBar MinHeight="60">
<AppBarButton x:Name="Command_BarButton" Icon="AllApps"
Label="Seletie"
Click="AppBar_Select"/>
</CommandBar>
</Page.BottomAppBar>
I would like to change the AppBarButton icon programatically in C# to another prexistent icon, like the Trash icon. How can i do this ?
Command_BarButton.Label = "Delete";
Command_BarButton.Icon = ?
I knew it would be very easy to change the AppBarButton Icon at runtime.
This is how:
Command_BarButton.Label = "Delete";
Command_BarButton.Icon = new SymbolIcon(Symbol.Delete);
Thanks to this link
to change Icon from code behind try this
ApplicationBar = new ApplicationBar();
ApplicationBarIconButton button1 = new ApplicationBarIconButton();
button1.IconUri = new Uri("/Images/play.png", UriKind.Relative);
button1.Text = "play";
ApplicationBar.Buttons.Add(button1);
source
this shuold help
<AppBarButton Label="BitmapIcon" Click="AppBarButton_Click">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/globe.png"/>
</AppBarButton.Icon>
</AppBarButton>
source
This might be a trivial beginner question and I have found quite a bit of related information for Windows and Silverlight apps but nothing that would directly help me. I'm writing a Windows Phone 8.1/WinRT app in C# and XAML, and I would like to programmatically modify application bars created in XAML. For instance, there is a button I want to include in debug builds only, using preprocessor directives in code behind.
In the following XAML code I'm creating a BottomAppBar with two buttons. How can I create the second button (AppBarAddSampleItemsButton) including all properties in code behind?
<prism:VisualStateAwarePage.BottomAppBar>
<CommandBar >
<CommandBar.PrimaryCommands>
<AppBarButton x:Uid="AppBarNewItemButton"
Label="New item"
Icon="Add" Command="{Binding GoToAddItemPageCommand}" />
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton x:Uid="AppBarAddSampleItemsButton"
Label="Add sample items"
Command="{Binding GoToAddSampleItemssPageCommand}" />
</CommandBar.SecondaryCommands>
</CommandBar>
</prism:VisualStateAwarePage.BottomAppBar>
Here is a sample code creating an AppBarButton in the code behind and adding it to BottomAppBar of the current Page:
private void AddButtonToAppBar()
{
AppBarButton buttonToAdd = new AppBarButton { Label = "Label", Icon = new SymbolIcon(Symbol.Help) };
buttonToAdd.Click += async (sender, e) => await new MessageDialog("Button clicked").ShowAsync();
// add button to Page's BottoAppBar
(BottomAppBar as CommandBar).PrimaryCommands.Add(buttonToAdd);
}
Edit - as for Binding (again from the top of my head, so you will have to check this) this should probably work:
Binding myBind = new Binding();
myBind.Path = new PropertyPath("GoToAddSampleItemssPageCommand");
myBind.Source = DataContext;
buttonToAdd.SetBinding(AppBarButton.CommandProperty, myBind);
More about DataBinding at MSDN.
After some digging around on the Windows Phone dev center, I found this page: How to change app bar icon buttons and menu items dynamically for Windows Phone. Hope it helps!
I'm writing a Windows Phone 8.1 app and I would like to get binding Tapped event (e.g. for Grid) capability. I read many articles and answers, but all solutions don't work in my situation. Does it exist any alternative to triggers (System.Windows.Interactivity) or Command for WP 8.1?
Thanks for interest, but I found solution. I probably was too tired and I forgot add reference to Behaviors SDK. It works great now.
<Page
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core" ...>
And simple Command usage:
<SomeControl ...>
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding MyCommand}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</SomeControl>