2013-10-28 28 views
0

我的Visual Studio 2010的設計師與此錯誤崩潰使用+時:Visual Studio的WPF設計崩潰的結合

Error 3 Type 'vm:MessageViewModel+MessageAction' was not found. 

這是導致錯誤的行:

<Button Content="View" Command="{Binding Path=ActionCommand}" CommandParameter="{x:Static vm:MessageViewModel+MessageAction.OpenView}"/> 

記住該程序編譯並運行良好。該參數甚至可以正確傳遞給該命令。

枚舉是在一個類中,所以我需要使用加號來引用它。這是班級結構:

public class MessageViewModel : ModelWrapViewModel<MessageModel> 
{ 
    private ICommand _actionCommand; 

    public enum MessageAction 
    { 
     OpenView, 
     OpenNote, 
     OpenAcknowledge, 
     Cancel, 
     Save, 
     Acknowledge 
    } 

    public ICommand ActionCommand 
    { 
     get 
     { 
      if (_actionCommand == null) 
      { 
       _actionCommand = new RelayCommand(
        param => this.DoSomething((MessageAction)param), 
        param => true 
       ); 
      } 
      return _actionCommand; 
     } 
    } 

} 

只是想知道是否有一個原因,這在VS設計師不起作用。如果我移動MessageViewModel類的枚舉之外的設計器不會崩潰。

+0

你不能這樣做嗎? 'vm:MessageViewModel.MessageAction.OpenView' – sthotakura

+0

沒有在WPF語法上不正確。如果你想在xaml的類中引用類型,你可以使用'+'。使用'.'將不會編譯,所以這是一個倒退。 – baueric

+0

好的,謝謝你的信息:) – sthotakura

回答

1

視覺工作室可能會痛苦有時沒有?不知道這是否會有所幫助,但可以將它作爲動態資源,因此只能在運行時加載。希望這有助於 - Rick CommandParameter =「{DynamicResource {x:Static vm:MessageViewModel + MessageAction.OpenView}}」/>

+0

感謝您的回覆。這對我來說無論是在設計師還是在我運行程序時都不起作用。 – baueric