2012-05-10 34 views
0

我在執行位於DataGridTemplateColumn.CellTemplate - > DropDownButton中的按鈕時遇到了一些問題。 Fyi,該按鈕嵌入在用戶控件中。代碼如下:無法從包含在擴展工具包中的用戶控件中的按鈕觸發事件DropDownButton

DataGrid列模板:

<Custom:DataGridTemplateColumn Header="Status"> 
         <Custom:DataGridTemplateColumn.CellTemplate> 
          <DataTemplate> 
           <extToolkit:DropDownButton Width="Auto" 
                  Height="Auto" 
                  Content="Request"                
                  > 
            <extToolkit:DropDownButton.DropDownContent> 
             <local:ButtonGroup /> 
            </extToolkit:DropDownButton.DropDownContent> 
           </extToolkit:DropDownButton> 
          </DataTemplate> 
         </Custom:DataGridTemplateColumn.CellTemplate> 
        </Custom:DataGridTemplateColumn> 

視圖模型:

ButtonSetStatusEvent = new RelayCommand(new Action<object>(SetStatus)); 

public ICommand ButtonSetStatusEvent 
{ 
    get 
    { 
    return m_ButtonSetStatusEvent; 
    } 
    set 
    { 
    m_ButtonSetStatusEvent = value; 
    } 

} 

private void SetStatus(object o) 
{ 

    if (o.ToString() == "CmdWait") 
    { 
    coStatus = (int)Status.Waiting; 
    CoStatusDisplay = Status.Waiting.ToString(); 
    } 
} 

按鈕觸發XAML:

<i:Interaction.Triggers> 
       <i:EventTrigger EventName="Click">       
         <cmd:EventToCommand Command="{Binding RelativeSource= {RelativeSource FindAncestor, 
         AncestorType=local:GridOverview, 
         AncestorLevel=1}, 
         Path=DataContext.ButtonSetStatusEvent}" 
         CommandParameter="CmdWait" 
         PassEventArgsToCommand="False" />      

       </i:EventTrigger> 
      </i:Interaction.Triggers> 

那麼,如何使人們有可能火點擊按鈕的事件? 非常感謝!

+0

您是否嘗試過使用按鈕的Command屬性而不是使用觸發器。默認情況下點擊調用該命令。 – Slugart

+0

嘗試但沒有運氣..但它會工作,如果我把用戶控件(其中包含按鈕)直接到DataGridRow(除了投入DropDownButton) – anevil

回答

0

通過實現ViewModelLocator來解決

相關問題