2

WPF/XAML を理解するための継続的な試みの一環として、流暢なインターフェイスを UI コーディングに適用することに興味を持つようになりました。

Fluent Silverlight ( http://code.google.com/p/fluent-silverlight/ ) は認識していますが、WPF に相当するものを見つけることができないようです。

個人的なメモとして、XAML と C#/MVVM を組み合わせてすべてを実行することに同意するのは非常に難しいと感じています。UI プログラミングの特定の側面 (データ バインディングなど) は、宣言型 XAML よりもコードで表現したほうがよいように思えます。

流暢な WPF インターフェイスは、これらの目標を達成するためのもののようです。

4

3 に答える 3

2

Herding Code の最近のポッドキャスト: http://herdingcode.com/?p=212で、ゲストの 1 人が、WPF UI を作成するための流暢なインターフェイスを試みたことについて話し合っています。そのうちの 1 人が、彼らが行ったことを利用可能にすることができる可能性があります。

ちなみに、この同じポッドキャストとその前のポッドキャスト ( http://herdingcode.com/?p=208 ) では、コード ファーストとビュー ファーストの関係と、xaml に集中することが有利な理由について説明しています。

の議論は主に、コードのテスト容易性に加えて、デザイナーが UI を "ブレンド可能" (Microsoft Expression Blend でデザインできるようにすること) にすることに関するものです。コードベースのアプローチは、あまり注意しないと、この能力を弱めます。

不安を感じているのはあなただけではありません。うまくいけば、これらのポッドキャストが決定を下すのに役立ちます.

于 2009-08-28T17:43:31.943 に答える
2

流暢なスタイルでプログラミングしたい WPF の部分に出くわしたら、サポートする拡張メソッドを個人用ユーティリティ アセンブリに追加します。

たとえば、TaskbarItemInfo ProgressValueおよびProgressStateプロパティを示すプログラムを次に示します。このバージョンは、標準的な非流暢な方法で書かれています。

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(の代わりに) の 2 つの拡張メソッドを採用してClick += ...います。

プログラムは次のようになります。

ここに画像の説明を入力

個人のFluentWpf ライブラリは github に置いています。

于 2012-04-19T00:05:25.993 に答える
1

WPF でコマンドを作成するための流暢な API http://code.google.com/p/present/

于 2010-09-07T10:16:33.033 に答える