我试过阅读文章WPF/Silverlight: Step By Step Guide to MVVM,但我完全无法理解它。将View代码保留在View代码中不好吗?
但是我noticied这样的方针:
那是你的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代码?这看起来像很糟糕的设计... –
看起来是重复http://stackoverflow.com/questions/3878610/why-keep-code-behind-clean-and-do-everything-in-xaml –