1

我正在尝试在页面中放置一个集线器,但似乎 Binding 无法正常运行。我使用了 Template10 Hamburger 示例并尝试在主页中放置一个集线器。在我测试时,我只是将现有的堆栈面板封装在集线器部分内,但它似乎破坏了按钮单击事件的绑定。

构建时出错

你调用的对象是空的

<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>
4

2 回答 2

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>
于 2016-02-12T16:24:59.277 回答
0

我当然可以向你解释这个问题。因为您正在使用集线器控件,并且集线器控件使用集线器部分,并且因为集线器部分与工具箱中的几乎任何其他控件不同,它使用数据模板来绘制其内容,所以数据模板中每个元素的数据上下文都不是更长的外部页面的数据上下文。也就是说,您的绑定失败是因为您正在绑定到一个没有您需要的方法的新类。

至于解决方案,您可以这样做:

<Core:CallMethodAction MethodName="GotoDetailsPage" TargetObject="{Binding ElementName=ViewModel}" />

该语法会将您的上下文带回页面的视图模型。但是您的解决方案似乎对您有用。我会坚持什么有效。

祝你好运。

于 2016-02-12T21:51:43.953 回答