【发布时间】:2011-11-11 20:44:18
【问题描述】:
我尝试阅读文章WPF/Silverlight: Step By Step Guide to MVVM,但我无法完全理解。
但是我注意到了这样的准则:
那是你的 View.xaml.cs 应该几乎没有代码。
我应该如何修复下面的代码?我应该将我的 WCF 代码提取到另一个地方吗?谢谢。
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ChannelFactory<IManagementConsole> pipeFactory =
new ChannelFactory<IManagementConsole>(
new NetNamedPipeBinding(),
new EndpointAddress(
"net.pipe://localhost/PipeManagementConsole"));
IManagementConsole pipeProxy =
pipeFactory.CreateChannel();
List<ConsoleData> datas = new List<ConsoleData>();
foreach (StrategyDescriptor sd in pipeProxy.GetStrategies())
{
datas.Add(pipeProxy.GetData(sd.Id));
}
dataGrid1.ItemsSource = datas;
}
}
【问题讨论】:
-
为什么视图中有 WCF 代码?这看起来很糟糕的设计......