XAML綁定組合框一個ListView裏面一個的ObservableCollection <string>
<UserControl x:Class="PatientsInscrit_GMF.ListDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:custom="clr-namespace:PatientsInscrit_GMF"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<ListView Grid.Row="1" Margin="0,0,0,0" x:Name ="FileList">
<ListView.View>
<GridView>
<GridViewColumn Header="Tag" Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox ></ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</UserControl>
.CS
namespace PatientsInscrit_GMF
{
public partial class ListDisplay : UserControl
{
private ObservableCollection<string> _tags;
public ObservableCollection<string> Tags
{
get { return _tags; }
}
public ListDisplay()
{
InitializeComponent();
_tags = new ObservableCollection<string>();
List<string> tags = Facade.Instance.RetrieveTags();
foreach(string s in tags)
{
_tags.Add(s);
}
}
}
}
如何綁定標籤到我的組合框,這是在我的列表視圖的列中的一個?
我試圖
ItemsSource = "{Binding Tags}"
但組合框保留爲空。我知道門面列表檢索不是空的,因爲它創建時我添加了2個默認標籤,以便它不是空的。
我嘗試了各種其他的解決方案,我發現並沒有工作,甚至有代碼示例,甚至不會編譯。
請幫助:)
不知道我關注你嗎? ItemsSource = {binding ...}那是綁定?正如我所說我嘗試了多種解決方案,我發佈的XAML是我需要添加綁定的乾淨狀態。你應該至少讀取所有的問題 – Fawar 2014-11-14 17:11:09