【发布时间】:2018-10-09 20:21:22
【问题描述】:
我的目标是:带有 Jira 帐户名称列表的 ComboxBox 和 ListView,它将显示在 ComboBox 中选择用户时发送到 jira 的查询的响应(因为帐户名称是查询的一部分)。
我所拥有的:对 C#、WPF、MVVM 和 工作解决方案(代码如下)知之甚少,但无论如何它都不是 MVVM。所以,我已经阅读了很多关于 MVVM(relayCommand、PropertyChanged 等)的内容,但由于某种原因,我无法提出如何将该程序重构为 MVVM 的解决方案。最大的问题之一是我无法弄清楚如何向 Jira 发出该请求并导致 IQueryable 的形式适合 MVVM 模式。我的意思是,我应该把它放在哪里。
所以,请如果有人能提示我一般应该怎么做才能将此程序转换为遵循 MVVM 模式或任何其他类型的建议,我将非常感激!
MainWindow.xamls.cs
public ObservableCollection<Issue> Issues { get; set; }
private void OnNameComboChanged(object sender, EventArgs e)
{
Issues.Clear();
string name = ((sender as ComboBox).SelectedItem as ComboBoxItem).Content as string;
Issues fetchedIssues = new Issues();
var issuesList = fetchedIssues.FetchIssues(name); // returns the list of Issues in a type of --> IQueryable<Issue>
foreach (var issue in issuesList)
{
Issues.Add(issue);
}
}
public MainWindow()
{
Issues = new ObservableCollection<Issue>();
InitializeComponent();
}
MainWindow.xaml
<Controls:MetroWindow x:Name="Main_Window" x:Class="Dull.MainWindow"
........
DataContext="{Binding RelativeSource={RelativeSource Self}}"> <!-- how I link contexts-->
<Controls:MetroWindow.RightWindowCommands>
<Controls:WindowCommands>
<ComboBox x:Name="Name" SelectionChanged="OnNameComboChanged" > <!-- Combox box with nicknames -->
<ComboBoxItem>name of the user</ComboBoxItem>
<ComboBoxItem>another name of the user</ComboBoxItem>
</ComboBox>
</Controls:WindowCommands>
</Controls:MetroWindow.RightWindowCommands>
<Grid>
<ListView x:Name="issuesListView" ItemsSource="{Binding Issues}"> <!-- ListView binded to Issues collection -->
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Summary}"
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
【问题讨论】:
标签: c# wpf mvvm jira-rest-api