比方說,我有一個結合的東西,在代碼隱藏列表框:後面數據綁定在XAML(可多方式結合?)
<ListBox x:Name="list">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem Content="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox x:Name="name" Text="{Binding ElementName=list, Path=SelectedItem.Name, Mode=TwoWay" />
<TextBox x:Name="contents" Text="{Binding ElementName=list, Path=SelectedItem.Contents, Mode=TwoWay" />
代碼:
public class Dude
{
public String Name { get; set; }
public String Contents { get; set; }
}
現在上面並正是我想要的。選擇列表框中的項目時,文本框將更新以顯示在列表框中選擇的內容。
但是現在我要做的是通過添加字典將它擴大我的哥們類:
public class Dude
{
public string Name { get; set; }
public string Contents { get; set; }
public Dictionary<String, String> Tasks { get; set; }
}
在希望,我可以:
中單擊某個項目列表框中,將相應項目的名稱和 內容屬性顯示在其各自的文本框中,然後 向內容文本框追加內容的鍵值/字典的 內容。
但我不知道我該如何去那麼深。它有點覺得我要去多層次,像多維的綁定是我需要的東西?
是否有任何(簡單)樣品您有或已經看到?文檔,文章,教程?
任何幫助,非常感謝。
謝謝
我認爲更好的解決方案可能會涉及您綁定到Tasks屬性的列表框或其他ItemsControl,而不是將Tasks對添加到已綁定到Contents屬性的控件。但是我已經完成了XAML綁定已經很長時間了,所以我現在恐怕沒有更好的答案。祝你好運! – phoog
這可能是使用的http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/ – user3357963
你的字典必須是靜態或我不看到使用。你可以做的是改變綁定,使其通知目標更新,然後捕獲TargetUpdated事件。 (http://msdn.microsoft.com/en-us/library/system.windows.data.binding.notifyontargetupdated.aspx) – GameAlchemist