Вопрос

My problem is with event. In AppBar all events, which I to inventend, they didn't to worked. (MessageDialog or other event ), when AppBar to showed, I can't hiding, and In AppBar didn't to worked click in button.

<Page.BottomAppBar>
<AppBar x:Name="AppBar" Background="#FF1DB05F">         
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">                  
        <Button x:Name="SaveButton" Style="{StaticResource AppBarButtonStyle}"
         Content="&#xE105;"

         AutomationProperties.Name="Save" >                       
           <WinRtBehaviors:Interaction.Behaviors>        
                <Win8nl_Behavior:EventToCommandBehavior Event="Tapped"

                                          Command="NewFileXml"

                                          />     
            </WinRtBehaviors:Interaction.Behaviors>

        </Button>

In MainViewModel.cs

public async void NewFileXml()
        {

            XmlDocument dom = new XmlDocument();
            XmlComment comment = dom.CreateComment("This is Goal a Year");
            XmlElement x;
            dom.AppendChild(comment);
            x = dom.CreateElement("Goal of a Year");
            dom.AppendChild(x);

            XmlElement stepXml = dom.CreateElement("Goalyear");
            XmlElement goalYearXml = dom.CreateElement("GoalStep");
            stepXml.InnerText = GoalYear;
            goalYearXml.AppendChild(stepXml);

            Windows.Storage.StorageFolder sf = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFolderAsync("GoalPlan");
            StorageFile st = await sf.CreateFileAsync("GoalYear.xml");
            await dom.SaveToFileAsync(st);
        }
        public  ICommand NewFile
        {
            get
            {
                return new RelayCommand(() =>
                    {

                        NewFileXml();

                    });
            }
        }

I did with help from Polish Microsoft. Maybe Someone that to add.

 private RelayCommand exampleContent;
            public RelayCommand ItIsBind
            {
                get
                {
                    return exampleContent ?? (exampleContent = new RelayCommand(ContentLoad));
                }
            }
**Method example**
public void ContentLoad()
{

}
Это было полезно?

Решение 2

There are a couple of possible issues here...

1) Your command is not named "NewFileXml", but "NewFile"
2) You don't appear to be setting your DataContext - are you doing this elsewhere (if so, you haven't shown it)

Другие советы

I'm not sure if this will work for you but in my case i had to place my appbar inside the main grid. So you copy this

<AppBar x:Name="AppBar" Background="#FF1DB05F">         
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">                  
    <Button x:Name="SaveButton" Style="{StaticResource AppBarButtonStyle}"
     Content="&#xE105;"

     AutomationProperties.Name="Save" >                       
       <WinRtBehaviors:Interaction.Behaviors>        
            <Win8nl_Behavior:EventToCommand etc...

without the

<Page.BottomAppBar> 

tags and paste it inside your main grid tags.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top