我需要將我的ObservableCollection<ValidationMessage>
放入我的TextBlock
。這是我的代碼。現在它顯示Item和SubItems,但消息顯示它有System.Collections.ObjectModel.ObservableCollection'1[ValidationWPF.DataSources.ValidationMessages]
。如何將ObservableCollection放入文本塊
我認爲這是因爲它不能把ObservableCollection
放入TextBlock
。
XAML:
<UserControl x:Class="ValidationWPF.ValidationUserControl"
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:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local="clr-namespace:ValidationWPF.DataSources"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<DataTemplate x:Key="Messages">
<TextBlock Text="{Binding Message}"/>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<telerik:RadTreeView x:Name="radTreeView" Margin="8">
<telerik:RadTreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding SubItems}">
<TextBlock Text="{Binding item}" />
</HierarchicalDataTemplate>
</telerik:RadTreeView.ItemTemplate>
</telerik:RadTreeView>
</Grid>
</UserControl>
ValidationMessage類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ValidationWPF.DataSources
{
public class ValidationMessage
{
public ValidationMessage(string Message)
{
this.Message = Message;
}
public string Message
{
get;
set;
}
}
}
ValidationItem類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
namespace ValidationWPF.DataSources
{
public class ValidationItem : ObservableCollection<ValidationItem>
{
public ValidationItem()
{
SubItems = new ObservableCollection<ValidationItem>();
}
public ObservableCollection<ValidationMessage> Message
{
get;
set;
}
public string item
{
get;
set;
}
public IList<ValidationItem> SubItems
{
get;
set;
}
public static IList<ValidationItem> GetItems(string name)
{
var Validation = new ObservableCollection<ValidationItem>();
var item = new ValidationItem();
item.item = "Customer";
var subItem = new ValidationItem();
subItem.item = "Name";
item.SubItems.Add(subItem);
var Message = new ValidationItem();
Message.item = new ObservableCollection<ValidationMessage>().ToString();
subItem.SubItems.Add(Message);
Validation.Add(item);
return Validation;
}
}
}
謝謝您的幫助!
這看起來像它可以工作。然後我怎麼能實現這個到我的hierarchicaldatatemplate使它顯示像客戶名稱消息(這應該像父母,孩子,孫子) – JLott