Я искал некоторое время, и ничего, что я пробовал, не решило проблему.Приведенный ниже код выполняется без ошибок, но в шаблоне не отображаются данные.
<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="GOReviewSL.UserControls.Announcements"
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"
d:DesignHeight="75" d:DesignWidth="280" xmlns:my="clr-namespace:Local;assembly=Local">
<Grid x:Name="LayoutRoot" Background="White">
<my:Fieldset Height="Auto" HorizontalAlignment="Left" Name="fieldset1" VerticalAlignment="Top">
<StackPanel VerticalAlignment="Top" Orientation="Vertical">
<sdk:DataGrid x:Name="AnnouncementsGrid" ItemsSource="{Binding}">
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Top" Orientation="Vertical">
<HyperlinkButton x:Name="AnnouncmentTitleLink" FontWeight="Bold" Content="{Binding Title}" Click="AnnouncmentTitleLink_Click" />
<TextBlock x:Name="AuthorText" Text="{Binding Author}" FontSize="10" FontStyle="Italic"/>
<TextBlock x:Name="AnnouncementText" Text="{Binding Title}"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</StackPanel>
</my:Fieldset>
<Image Source="/GOReviewSL;component/Images/announcements.png" Height="20" HorizontalAlignment="left" Margin="20,1,0,0" VerticalAlignment="Top"/>
</Grid>
Класс объявления:
public class Announcement
{
public string Author { get; set; }
public string Title { get; set; }
public string Text { get; set; }
public string ModifiedDate { get; set; }
public Announcement()
{
this.Author = string.Empty;
this.Title = string.Empty;
this.Text = string.Empty;
this.ModifiedDate = string.Empty;
}
public Announcement(string author, string title, string text, string modifiedDate)
{
this.Author = author;
this.Title = title;
this.Text = text;
this.ModifiedDate = modifiedDate;
}
}
Мой код привязки:
public Announcements()
{
InitializeComponent();
objController.ListAnnouncementsCompleted += new EventHandler<ListAnnouncementsCompletedEventArgs>(objController_ListAnnouncementsCompleted);
objController.ListAnnouncementsAsync();
}
void objController_ListAnnouncementsCompleted(object sender, ListAnnouncementsCompletedEventArgs e)
{
var objAnnouncements = from el in e.Result
select el;
AnnouncementsGrid.DataContext = objAnnouncements.ToList();
AnnouncementsGrid.ItemsSource = objAnnouncements.ToList();
}
Я менял этот последний бит несколько раз.Любая помощь будет принята с благодарностью!