Prism と MVVM パターンを使用してアプリケーションを開発しようとしています。私の UI では、前と次のボタンが定義されています。Web サービスの呼び出しで使用するために、トラバースする必要がある方向を示す列挙型を定義しました。したがって、この例では、ボタンは列挙値に直接マップされます。列挙型の定義は非常に単純で、次のとおりです。
namespace CodeExpert.Book.Helpers
{
public enum BookDirection { Previous = -1, NotSet = 0, Next = 1, }
}
ViewModel でコマンドとデリゲートを定義し、プロパティを正しく割り当てました。関連するコードは次のとおりです。
public DelegateCommand PreviousNextCommand { get; set; }
public IndexEntriesViewModel(GlobalVariables globalVariable, IndexEntryOperations currentOperator)
{
//a bunch of initialization code.
InitializeCommands();
}
void InitializeCommands()
{
PreviousNextCommand =
new DelegateCommand(OnPreviousNextCommandExecute);
}
private void OnPreviousNextCommandExecute(BookDirection parameter)
{
//Code to process based on BookDirection
}
したがって、この構成に基づいて、BookDirection 列挙値を CommandParameter に渡したいと思います。ただし、これに適した XAML を取得することはできません。私が試した中で最も正しいと思われるXAMLは次のとおりです。
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="CodeExpert.Book.Views.Index"
d:DesignWidth="1024"
d:DesignHeight="768"
xmlns:helpers="clr-namespace:CodeExpert.Book.Helpers"
xmlns:command="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input">
<Button x:Name="ButtonPrevious"
HorizontalAlignment="Left"
Margin="2,1,0,1"
Width="25"
Content="<"
Grid.Column="1"
Grid.Row="1"
Height="20"
command:Click.Command="{Binding Path=CurrentIndexViewModel.PreviousNextCommand}">
<command:Click.CommandParameter>
<helpers:BookDirection.Previous />
</command:Click.CommandParameter>
</Button>
</UserControl>
列挙型の BookDirection のインテリセンスが得られず、設計時およびコンパイル時に、型 'BookDirection' に 'Previous' の定義が含まれていないというエラーが表示されます。その列挙型を渡す方法はありませんか、それとも単に何か不足していますか? パラメータタイプをstring
ではなく に設定することで動作するようになりましBookDirection
たが、テキストを解析する必要があり、コードの匂いがします。私はいくつかのGoogle検索を行いましたが、答えに最も近いものはここにあります - Passing an enum value as command parameter from XAML残念ながら、Silverlightはx:staticバインディング拡張をサポートしていないため、使用できませんその回答で説明されている正確な手法。
どんな助けでも大歓迎です。