Задайте вопросЗадайте вопрос
 

ОтвеченоComboBox Data Binding in XAML

  • 10 февраля 2009 г. 3:22Forum Craig Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     С кодом

    Hi

    The ComboBox data binding is on a DataTable which is returned from a method call on a singleton instance object.

    Here is my XAML

    <Window x:Class="MainWindow" 
        xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation  
        xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml  
        xmlns:data="clr-namespace:System.Data;assembly=System.Data" 
        Title="Database" Height="495" Width="420" ResizeMode="CanResizeWithGrip">  
        <Window.Resources> 
            <ObjectDataProvider x:Key="DataTable" 
                ObjectType="{x:Type data:Sql.SqlDataSourceEnumerator}"/>   
        </Window.Resources> 
        <StackPanel> 
            <ComboBox Name="comboBoxServer"   
                ItemsSource="{Binding Source=  
                    {x:Static data:Sql.SqlDataSourceEnumerator.Instance}}"   
                DisplayMemberPath="ServerName" /> 
        </StackPanel> 
    </Window> 
     

    The method I want to call is GetDataSources(), for example in code it would appears:

    System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();

    So the question is, how do I declarative make this call using XAML binding the return DataTable to a ComboBox?

    Craig

Ответы

  • 10 февраля 2009 г. 7:05Forum Craig Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     ОтвеченоС кодом
    Solution

    <Window x:Class="MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:data="clr-namespace:System.Data;assembly=System.Data" 
        Title="Database" Height="495" Width="420" ResizeMode="CanResizeWithGrip">  
        <Window.Resources> 
            <ObjectDataProvider   
                x:Key="DataTable" 
                ObjectInstance="{x:Static data:Sql.SqlDataSourceEnumerator.Instance}" 
                MethodName="GetDataSources" 
                IsAsynchronous="True"/>         
        </Window.Resources> 
    <StackPanel> 
                    <ComboBox ItemsSource="{Binding Source={StaticResource DataTable}, Mode=OneWay}" DisplayNamePath="ServerName"/>  
    </StackPanel> 
    </Window> 
    • Помечено в качестве ответаForum Craig 10 февраля 2009 г. 7:06
    •  

Все ответы