Ste*_*ard 5 c# silverlight enums xaml prism
我正在尝试使用Prism和MVVM模式来开发应用程序.在我的UI中,我定义了上一个和下一个按钮.为了在调用Web服务中使用,我已经定义了一个枚举,它将告诉我需要遍历的方向.因此,在这种情况下,按钮直接映射到枚举值.枚举定义非常简单,如下:
namespace CodeExpert.Book.Helpers
{
public enum BookDirection { Previous = -1, NotSet = 0, Next = 1, }
}
Run Code Online (Sandbox Code Playgroud)
我在我的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
}
Run Code Online (Sandbox Code Playgroud)
因此,基于此配置,我想将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>
Run Code Online (Sandbox Code Playgroud)
对于枚举的BookDirection,我没有得到intellisense,并且在设计和编译时遇到错误,说'BookDirection'类型不包含'Previous'的定义.有没有办法通过那个枚举,或者我只是遗漏了什么?我现在通过设置参数类型来实现它,string而不是BookDirection,但是我必须解析文本和代码气味.我已经完成了一些谷歌搜索,而我最接近答案的就是这里 - 将一个枚举值作为命令参数传递给XAML不幸的是,Silverlight不支持x:static绑定扩展,所以我不能使用该答案中描述的确切技术.
任何帮助将非常感激.
| 归档时间: |
|
| 查看次数: |
5950 次 |
| 最近记录: |