WinRT:以编程方式设置下拉列表源

时间:2014-09-06 13:19:38

标签: sqlite xaml drop-down-menu windows-runtime

我有一个DropDown列表和2个Radio Buttons。每个按钮更改一次我需要更改DD列表数据源。

XAML:

<Page
    x:Class="myapp.MyTags"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ReqWriter8"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" Loaded="Page_Loaded">
  <Page.Resources>
    <CollectionViewSource x:Name="MyAxureHTML"  Source="{Binding }"/>
    <CollectionViewSource x:Name="MyControlTypeIDs"  Source="{Binding }"/>
  </Page.Resources>

  <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="480*"/>
      <ColumnDefinition Width="203*"/>
    </Grid.ColumnDefinitions>
    <!-- Back button and page title -->
    <Grid x:Name="titlePanel" Background="Gray" Grid.ColumnSpan="2">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="120"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <!--Command="{Binding NavigationHelper.GoBackCommand, ElementName=MainPage}"-->
      <Button x:Name="backButton" Margin="39,59,0,0" 
                        Style="{StaticResource BackButtonStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button" Width="71"/>
      <TextBlock x:Name="pageTitle" Text="Setup Requirement Statements" Style="{StaticResource HeaderTextStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Top" Margin="2,63,-2,0"/>
    </Grid>

    <RadioButton x:Name="btA" Content="Axure HTML" HorizontalAlignment="Left" Margin="353,184,0,0" VerticalAlignment="Top"/>
    <RadioButton x:Name="btB" Content="Balsamiq XML" HorizontalAlignment="Left" Margin="542,184,0,0" VerticalAlignment="Top"/>
    <ComboBox x:Name="cbWidget" HorizontalAlignment="Left" Margin="356,297,0,0" VerticalAlignment="Top" Width="307" MaxDropDownHeight="15"/>


  </Grid>
</Page>

代码:

Private Sub Init()
    Dim dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, App.DB)
    Using db = New SQLiteConnection(dbpath)

      tblAxureHTML = From T In db.Table(Of AxureHTML)()
                       Where T.ClassName IsNot Nothing
                       Select T
      tblControlTypeIDs = From T In db.Table(Of ControlTypeIDs)()
                       Where T.Name IsNot Nothing
                       Select T


      MyAxureHTML.Source = tblAxureHTML
      MyControlTypeIDs.Source = tblControlTypeIDs

      db.Dispose()
      db.Close()

    End Using
    cbWidget.ItemsSource = MyAxureHTML
  End Sub

DB:SQLite

首先我不知道如何设置DropDown源列表。 其次,需要在选择单选按钮时进行更改。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

要触发加载列表,您可以在Checked s上注册RadioButton事件:

<RadioButton x:Name="fruitsChoiceInput" Checked="RadioButton_Checked">Fruits</RadioButton>
<RadioButton x:Name="vegetablesChoiceInput" Checked="RadioButton_Checked">Vegetables</RadioButton>
<ComboBox x:Name="listOutput"></ComboBox>

要设置列表,您可以使用ItemsSource的{​​{1}}属性:

ComboBox