2011-11-11 6 views
0

新しい暗黙的なデータテンプレートが大好きですが、問題が発生しました。Silverlight 5:暗黙的なデータテンプレートを使用してComboboxを停止する方法

My ComboBoxは、DisplayMemberPath設定の代わりにItemsSourcesタイプに一致するDataTemplateを選択しています。コントロールにDataTemplatesを探すように指示する方法はありますか?

 <ComboBox DisplayMemberPath="DTO.Name" SelectedValue="{Binding DefaultModifierGroup, Mode=TwoWay}" 
ItemsSource="{Binding MenuRepository.ModifierGroups, Source={StaticResource Locator}}"/> 

答えて

1

もうDisplayMemberPathを使用できないと思います。おそらく、そのコンボボックス内に新しいデータテンプレートを作成する必要があります。

<UserControl x:Class="SilverlightApplication1.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    xmlns:local="clr-namespace:SilverlightApplication1" 
    d:DesignHeight="300" d:DesignWidth="400"> 
    <UserControl.Resources> 
     <DataTemplate DataType="local:Person"> 
      <TextBlock Text="{Binding Address}" /> 
     </DataTemplate> 
    </UserControl.Resources> 
    <Grid x:Name="LayoutRoot" Background="White"> 
     <StackPanel> 
      <ListBox ItemsSource="{Binding Items}" /> 
      <ListBox ItemsSource="{Binding Items}" > 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <TextBlock Text="{Binding Name}" /> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 
     </StackPanel> 
    </Grid> 
</UserControl> 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 

namespace SilverlightApplication1 { 
    public partial class MainPage : UserControl { 
     public MainPage() { 
      this.DataContext = this; 
      InitializeComponent(); 

      Items = new List<Person>{ 
       new Person() { Name ="Name1", Address ="Address1" }, 
       new Person() { Name ="Name2", Address ="Address2" }, 
       new Person() { Name ="Name3", Address ="Address3" } 
      }; 

     } 

     public IList<Person> Items { get; set; } 

    } 

    public class Person { 
     public string Name { get; set; } 
     public string Address { get; set; } 
    } 
} 
+0

コードは、私はこれが解決に必要なことです私は覚えていないことができますが、私はこれは私がやってしまったものですかなり確信しています。回答を投稿してくれてありがとう、うまくいけば他の人にも役立つ! –

関連する問題