集线器绑定在Template10中不起作用

时间:2016-02-12 04:05:39

标签: winrt-xaml win-universal-app template10

我试图将一个集线器放在一个页面中,但似乎Binding功能不正确。我使用了Template10 Hamburger示例并试图在主页面中放置一个集线器。在我测试时,我只是将现有的stackpanel封装在一个hub部分中,但它似乎打破了按钮点击事件的绑定。

构建时出现

错误:

  

对象引用未设置为对象的实例

<HubSection>
    <DataTemplate>
        <StackPanel Grid.Row="1" VerticalAlignment="Top" Orientation="Horizontal"
        Padding="12,8,0,0">

            <controls:Resizer>
                <TextBox Width="200" MinWidth="200" MinHeight="60"
             Margin="0" Header="Parameter to pass"
             Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
             TextWrapping="Wrap">
                    <Interactivity:Interaction.Behaviors>
                        <Behaviors:TextBoxEnterKeyBehavior>
                            <Core:CallMethodAction MethodName="GotoDetailsPage" TargetObject="{Binding}" />
                        </Behaviors:TextBoxEnterKeyBehavior>
                        <Core:EventTriggerBehavior>
                            <Behaviors:FocusAction />
                        </Core:EventTriggerBehavior>
                    </Interactivity:Interaction.Behaviors>
                </TextBox>
            </controls:Resizer>
            <Button Margin="12,0" VerticalAlignment="Bottom"
        Click="{x:Bind ViewModel.GotoDetailsPage}" Content="Submit" />
        </StackPanel>
    </DataTemplate>
</HubSection>

2 个答案:

答案 0 :(得分:1)

最后设法点击按钮使用行为交互进行绑定。下面是代码。如果其他人有更好的建议,请随时发表评论。

    <Button Margin="12,0" VerticalAlignment="Bottom" Content="Submit" >
        <Interactivity:Interaction.Behaviors>
            <Core:EventTriggerBehavior EventName="Click">
                <Core:CallMethodAction MethodName="GotoDetailsPage" TargetObject="{Binding}" />
            </Core:EventTriggerBehavior>
        </Interactivity:Interaction.Behaviors>
    </Button>

答案 1 :(得分:0)

I can certainly explain the problem to you. Because you are using the hub control and because the hub control uses hub sections and because the hub section, unlike almost any other control in your toolbox, uses data templates to draw its content, the data context of every element inside the data template is no longer the data context of the outside page. That is to say, your binding fails because you are binding to a new class that does not have the method you need.

As for a solution, you could have done this:

.gradle

That syntax would have brought your context back to the page's view model. But your solution seems to work for you. I would stick with what works.

Best of luck.