首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MVVM Windows 8 appBar mvvm事件

MVVM Windows 8 appBar mvvm事件
EN

Stack Overflow用户
提问于 2013-01-14 22:31:11
回答 2查看 874关注 0票数 1

我的问题是事件。在我发明的AppBar所有事件中,它们都不工作。(MessageDialog或其他事件),当AppBar to显示时,我无法隐藏,并且在AppBar中没有工作来点击按钮。

代码语言:javascript
复制
<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>

在MainViewModel.cs中

代码语言:javascript
复制
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();

                    });
            }
        }

我是在波兰微软的帮助下做到的。也许有人要加进去。

代码语言:javascript
复制
 private RelayCommand exampleContent;
            public RelayCommand ItIsBind
            {
                get
                {
                    return exampleContent ?? (exampleContent = new RelayCommand(ContentLoad));
                }
            }
**Method example**
public void ContentLoad()
{

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-14 22:37:10

这里有几个可能的问题。

1)您的命令名不是NewFileXml,而是NewFile

2)你似乎没有设置你的DataContext -你在别处做了吗(如果是,你还没有显示出来)

票数 0
EN

Stack Overflow用户

发布于 2013-02-20 21:03:31

我不确定这是否适用于您,但在我的情况下,我必须将我的应用程序栏放在主网格中。所以你把这个拷贝下来

代码语言:javascript
复制
<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...

如果没有

代码语言:javascript
复制
<Page.BottomAppBar> 

标签,并将其粘贴到主网格标签中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14320377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档