Templates Silverlight 5:如何阻止组合框使用隐式数据模板
我喜欢新的隐式数据模板,但我刚刚遇到了一个问题 我的组合框正在选择与ItemsSources类型匹配的数据模板,而不是遵循我的DisplayMemberPath设置。有没有办法告诉控件不要查找数据模板Templates Silverlight 5:如何阻止组合框使用隐式数据模板,templates,combobox,silverlight-5.0,implicit,Templates,Combobox,Silverlight 5.0,Implicit,我喜欢新的隐式数据模板,但我刚刚遇到了一个问题 我的组合框正在选择与ItemsSources类型匹配的数据模板,而不是遵循我的DisplayMemberPath设置。有没有办法告诉控件不要查找数据模板 <ComboBox DisplayMemberPath="DTO.Name" SelectedValue="{Binding DefaultModifierGroup, Mode=TwoWay}" ItemsSource="{Binding MenuRepository.Modi
<ComboBox DisplayMemberPath="DTO.Name" SelectedValue="{Binding DefaultModifierGroup, Mode=TwoWay}"
ItemsSource="{Binding MenuRepository.ModifierGroups, Source={StaticResource Locator}}"/>
我想你不能再使用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; }
}
}
使用制度;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Animation;
使用System.Windows.Shapes;
命名空间SilverlightApplication1{
公共部分类主页面:UserControl{
公共主页(){
this.DataContext=this;
初始化组件();
项目=新列表{
新人(){Name=“Name1”,Address=“Address1”},
新人(){Name=“Name2”,Address=“Address2”},
新人(){Name=“Name3”,Address=“Address3”}
};
}
公共IList项{get;set;}
}
公共阶层人士{
公共字符串名称{get;set;}
公共字符串地址{get;set;}
}
}
我记不起我需要解决这个问题的代码在哪里,但我很确定这就是我最终要做的。谢谢你发布的答案,希望它对其他人也有帮助!