我試過閱讀文章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 –