没有 DataTemplate 的 HubSection(或者你可以在 HubSection 中有一个表单)?
HubSection without DataTemplate (or can you have a form in a HubSection)?
移植 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>
如果您想将表单直接放在 HubSection 的 DataTemplate 中,那么访问这些值的最佳方法是通过 data binding the TextBoxes to properties in your DataContext. The other option would be to crawl the visual tree by calling the VisualTreeHelper 从您的按钮的 SettingsSaveClickHandler
另一种选择是将表单创建为 UserControl,然后将完成的表单托管在 HubSection 的 DataTemplate 中。同样,您可以将它绑定到 DataContext 以连接到基础数据。
移植 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>
如果您想将表单直接放在 HubSection 的 DataTemplate 中,那么访问这些值的最佳方法是通过 data binding the TextBoxes to properties in your DataContext. The other option would be to crawl the visual tree by calling the VisualTreeHelper 从您的按钮的 SettingsSaveClickHandler
另一种选择是将表单创建为 UserControl,然后将完成的表单托管在 HubSection 的 DataTemplate 中。同样,您可以将它绑定到 DataContext 以连接到基础数据。