2009-08-28 67 views
2

作爲我一直試圖與WPF/XAML達成一致的一部分,我對將流暢接口應用於UI編碼感興趣。有沒有流利的WPF項目?

我知道流利的Silverlight(http://code.google.com/p/fluent-silverlight/),但我似乎無法找到任何等效WPF。

正如我個人而言,我發現很難購買到在XAML和C#/ MVVM的組合做的一切。在我看來,UI編程的某些方面(如數據綁定)在代碼中比在聲明式XAML中更好。

說一口流利的WPF界面似乎只是實現這些目標的事情。

回答

2

在最近的羊羣代碼播客:客人http://herdingcode.com/?p=212一個討論,他們試圖一口流利的界面,用於創建用戶界面WPF。他們中的一個可能會讓他們所做的事情變得可能。順便說一句,這個播客和它之前的播客(http://herdingcode.com/?p=208)分別講述了您對代碼優先和視圖優先的關注,以及爲什麼有必要關注xaml。

的爭論主要是有關使用戶界面「可混合」(能夠設計他們在Microsoft Expression Blend),設計者除了你的代碼的可測試性。如果你不是非常小心,基於代碼的方法會降低這種能力。

你不是一個人在你的疑慮。希望這些播客能幫助你做出決定。

+0

謝謝。 我已經聽了這兩個播客,並且實際上決定調查流暢的silverlight,因爲他們。 WPF包含很多很酷的東西 - 它只是一個搞清楚如何最好地使用(和打包)它們的問題。我曾經想過與MFC相當的MFC,但流暢的界面似乎是一個更好的方法。 其他人是否知道WPF的其他平衡評估?即既不完全負面也不完全盲目接受? – kmontgom 2009-08-28 19:41:36

+0

我還沒有聽說過很多。大多數人都喜歡我碰到的Xaml。這真的很糟糕。我個人喜歡它,現在很多。我認爲,如果我不得不去流暢的界面,我可能會覺得很麻煩,如果你能相信的話。 – 2009-08-29 05:48:15

+2

我喜歡使用XAML,但我想強烈的打字和其他類型的編譯類型檢查Fluent接口或任何其他基於代碼的方法可以提供的想法。處理數據綁定XAML的一部分內容是,您覺得自己回到Web上做試驗和錯誤代碼,並運行應用程序以查看它是否適用於編程類型。我寧願將其留給測試人員,但更糟糕的是測試人員甚至不會在默認情況下看到綁定錯誤,所以我們必須介紹我們自己處理WPF錯誤以從測試人員那裏獲得測試人員的反饋。遊民。 – jpierson 2011-04-02 05:56:05

2

當我碰上,我寧願在流利式編程WPF的部分建築的命令,我加上支持擴展方法到個人應用組件流利的API。

例如,下面的程序演示TaskbarItemInfoProgressValueProgressState屬性。此版本以標準不流利的方式編寫。

using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Shell; 

namespace TaskbarItemProgress 
{ 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 

      TaskbarItemInfo = new TaskbarItemInfo(); 

      TaskbarItemInfo.ProgressValue = 0.5; 

      var stackPanel = new StackPanel(); 

      Content = stackPanel; 

      var normalButton = new Button() { Content = "Normal" }; 
      normalButton.Click += (s, e) => 
       TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal; 
      stackPanel.Children.Add(normalButton); 

      var pausedButton = new Button() { Content = "Paused" }; 
      pausedButton.Click += (s, e) => 
       TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Paused; 
      stackPanel.Children.Add(pausedButton); 

      var errorButton = new Button() { Content = "Error" }; 
      errorButton.Click += (s, e) => 
       TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Error; 
      stackPanel.Children.Add(errorButton); 

      var indeterminateButton = new Button() { Content = "Indeterminate" }; 
      indeterminateButton.Click += (s, e) => 
       TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Indeterminate; 
      stackPanel.Children.Add(indeterminateButton); 

      var noneButton = new Button() { Content = "None" }; 
      noneButton.Click += (s, e) => 
       TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None; 
      stackPanel.Children.Add(noneButton); 

      var increaseButton = new Button() { Content = "Increase" }; 
      increaseButton.Click += (s, e) => TaskbarItemInfo.ProgressValue += 0.10; 
      stackPanel.Children.Add(increaseButton); 

      var decreaseButton = new Button() { Content = "Decrease" }; 
      decreaseButton.Click += (s, e) => TaskbarItemInfo.ProgressValue -= 0.10; 
      stackPanel.Children.Add(decreaseButton); 
     } 
    } 
} 

下面是一口流利的版本:

using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Shell; 
using FluentWpf; 

namespace TaskbarItemProgress 
{ 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 

      TaskbarItemInfo = new TaskbarItemInfo(); 

      TaskbarItemInfo.ProgressValue = 0.5; 

      Content = new StackPanel() 
       .AddChildren(
        new Button() { Content = "Normal" } 
         .AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal), 
        new Button() { Content = "Paused" } 
         .AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Paused), 
        new Button() { Content = "Error" } 
         .AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Error), 
        new Button() { Content = "Indeterminate" } 
         .AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Indeterminate), 
        new Button() { Content = "None" } 
         .AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None), 
        new Button() { Content = "Increase" } .AddClick((s, e) => TaskbarItemInfo.ProgressValue += 0.10), 
        new Button() { Content = "Decrease" } .AddClick((s, e) => TaskbarItemInfo.ProgressValue -= 0.10)); 
     } 
    } 
} 

流暢的版本是採用兩個擴展方法,AddChildren(而不是Children.Add)和AddClick(而不是Click += ...)。

程序是這樣的:

enter image description here

我把我的個人FluentWpflibrary on github