Manipulate application tables in Windows Phone 8.1 XAML from code

This might be a trivial question for beginners, and I found quite a bit of information related to Windows and Silverlight applications, but nothing helped me. I am writing a Windows Phone 8.1 / WinRT application in C # and XAML, and I would like to programmatically modify the application panels created in XAML. For example, there is a button that I want to include only in debug builds using preprocessor directives in the code.

In the following XAML code, I create a BottomAppBar with two buttons. How to create a second button (AppBarAddSampleItemsButton), including all the properties in the code?

<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>
+4
source share
2

, AppBarButton BottomAppBar :

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 BottoAppBar
    (BottomAppBar as CommandBar).PrimaryCommands.Add(buttonToAdd);
}

- ( , ), :

Binding myBind = new Binding();
myBind.Path = new PropertyPath("GoToAddSampleItemssPageCommand");
myBind.Source = DataContext;
buttonToAdd.SetBinding(AppBarButton.CommandProperty, myBind);

DataBinding MSDN.

+7

Windows Phone : Windows Phone. , !

0

All Articles