patterncsharpMinor
Display nested objects through custom displayers in WPF
Viewed 0 times
objectswpfcustomnestedthroughdisplayersdisplay
Problem
First off, I am very new to WPF. These are the objects I want to display:
The following is my XAML:
Within MainWindow.xaml
Within GithubIssue.xaml
GithubIssueComment.xaml
C# Code:
Main.xaml.cs:
`private async void ViewIssues_Click(object sender, RoutedEventArgs e)
{
grid.Children.Clear();
var apiClient = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("Issue-Managment"));
if (!string.IsNullOrWhiteSpace(userName.Text) && !string.IsNullOrWhiteSpace(repoName.Text))
{
var issuesClient = new IssuesWithCommentsClient(new Octokit.ApiConnection(apiClient.Connection));
var issues = await issuesClient.GetAllForRepositoryWithComments(userName.Text, repoName.Text);
Github
public class IssueWithComments
{
public Issue Issue { get; set; }
public IReadOnlyList Comments { get; set; }
public IssueWithComments()
{
Comments = new List();
}
}
// Simplified
public class Issue
{
public string Body { get; protected set; }
public Uri HtmlUrl { get; protected set; }
public IReadOnlyList Labels { get; protected set; }
public Milestone Milestone { get; protected set; }
public int Number { get; protected set; }
public PullRequest PullRequest { get; protected set; }
public ItemState State { get; protected set; }
public string Title { get; protected set; }}
public Uri Url { get; protected set; }
public User User { get; protected set; }
}
public class IssueComment
{
public string Body { get; protected set; }
public Uri HtmlUrl { get; protected set; }
public Uri Url { get; protected set; }
public User User { get; protected set; }
}The following is my XAML:
Within MainWindow.xaml
Within GithubIssue.xaml
GithubIssueComment.xaml
C# Code:
Main.xaml.cs:
`private async void ViewIssues_Click(object sender, RoutedEventArgs e)
{
grid.Children.Clear();
var apiClient = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("Issue-Managment"));
if (!string.IsNullOrWhiteSpace(userName.Text) && !string.IsNullOrWhiteSpace(repoName.Text))
{
var issuesClient = new IssuesWithCommentsClient(new Octokit.ApiConnection(apiClient.Connection));
var issues = await issuesClient.GetAllForRepositoryWithComments(userName.Text, repoName.Text);
Github
Solution
GithubIssue.xaml.cs:
This could be simplified with LINQ. How about:
public GithubIssue(IssueWithComments issue)
{
InitializeComponent();
this.DataContext = issue;
var commentDisplayers = new List();
foreach (var comment in issue.Comments)
{
commentDisplayers.Add(new GithubIssueComment(comment));
}
comments.ItemsSource = commentDisplayers;
}This could be simplified with LINQ. How about:
var commentDisplayers = issue.Comments.Select(comment=>new GithubIssueComment(comment)).ToList();
// or
var commentDisplayers = (from comment in issue.Comments select new GithubIssueComment(comment)).ToList();Code Snippets
public GithubIssue(IssueWithComments issue)
{
InitializeComponent();
this.DataContext = issue;
var commentDisplayers = new List<GithubIssueComment>();
foreach (var comment in issue.Comments)
{
commentDisplayers.Add(new GithubIssueComment(comment));
}
comments.ItemsSource = commentDisplayers;
}var commentDisplayers = issue.Comments.Select(comment=>new GithubIssueComment(comment)).ToList();
// or
var commentDisplayers = (from comment in issue.Comments select new GithubIssueComment(comment)).ToList();Context
StackExchange Code Review Q#88473, answer score: 4
Revisions (0)
No revisions yet.