【问题标题】:HubSection without DataTemplate (or can you have a form in a HubSection)?没有 DataTemplate 的 HubSection(或者你可以在 HubSection 中有一个表单)?
【发布时间】:2015-02-21 00:32:51
【问题描述】:

移植一个 iOS 应用程序,我可能会滥用集线器控制;但我有一个非常简单的应用程序,我希望将一个表单放在中心部分。但是,它似乎必须包装在 DataTemplate 中,并且一旦它是表单的 TextBox 控件就不会显示在 C# 文件后面的代码中?

<HubSection x:Uid="HubSection1" Header="SETTINGS"
                    DataContext="{Binding Groups[2]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
            <DataTemplate>
                <StackPanel VerticalAlignment="Top" Margin="0,0,20,0">
                    <TextBlock Text="api base uri" FontSize="21" TextWrapping="NoWrap"/>
                    <TextBox Name="apiBaseUriTextBox" Margin="0,0,0,10" TextWrapping="Wrap" PlaceholderText="api base uri" VerticalAlignment="Stretch"/>
                    <TextBlock Text="api key" FontSize="21" TextWrapping="NoWrap" Margin="0,0,0,10"/>
                    <TextBox Name="apiKeyTextBox" Margin="0,0,0,10" TextWrapping="Wrap" PlaceholderText="api key" VerticalAlignment="Stretch"/>
                    <TextBlock Text="api secret" FontSize="21" TextWrapping="NoWrap"/>
                    <TextBox Name="apiSecretTextBox" Margin="0,0,0,10" TextWrapping="Wrap" PlaceholderText="api secret" VerticalAlignment="Stretch"/>
                    <Button Click="SettingsSaveClickHandler" 
                        Content="Save" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,20,0,0"/>
                </StackPanel>
            </DataTemplate>
        </HubSection>

【问题讨论】:

    标签: c# xaml windows-store-apps windows-phone-8.1


    【解决方案1】:

    如果您想将表单直接放在 HubSection 的 DataTemplate 中,那么访问这些值的最佳方法是通过 data binding TextBoxes 到 DataContext 中的属性。另一种选择是通过从按钮的 SettingsSaveClickHandler 调用 VisualTreeHelper 来抓取可视化树

    另一种选择是将表单创建为 UserControl,然后将完成的表单托管在 HubSection 的 DataTemplate 中。同样,您可以将其绑定到 DataContext 以连接到底层数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多