2014-09-06 41 views
1

我有一個DropDown列表和2個單選按鈕。我需要更改每個按鈕更改DD列表數據源。WinRT:以編程方式設置DropDown列表來源

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的

首先,我不知道我怎麼設置下拉listt的來源。其次,需要在單選按鈕選擇上進行更改。

任何想法?

回答

0

要觸發列表的加載可以爲Checked事件的RadioButton S寄存器:

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

要設置列表中,您可以使用ComboBoxItemsSource屬性:

private static readonly string[] fruits = { "Apple", "Banana", "Kiwi" }; 
private static readonly string[] vegetables = { "Carrot", "Potato", "Tomato" }; 

private void RadioButton_Checked(object sender, RoutedEventArgs e) 
{ 
    listOutput.ItemsSource = fruitsChoiceInput.IsChecked == true ? fruits : 
     vegetablesChoiceInput.IsChecked == true ? vegetables : 
     null; 
} 
+0

好的,我自己找到了。現在問題是不同的。我的DropDown列表顯示對象字段的對象但不是對象的文本值。所以在CBox中,我有像Object.Field而不是字段值的txt!我需要在表單應用中設置名爲DisplayText的smth。 – Jalle 2014-09-06 20:31:56

+0

@Jalle所以你需要的是'DisplayMemberPath'。 – Pragmateek 2014-09-06 21:12:34