2013-05-31 45 views
2

我有以下的DataTemplate其在Resources.xaml(爲什麼沒有事件處理包括在這裏,多數民衆贊成)持有我的Visual模板爲我的節目定義添加事件處理程序的形狀一個DataTemplate內通過代碼

<DataTemplate x:Key="PointTemplate"> 
    <Ellipse x:Name="Ellipse" Width="8" Height="8" Stroke="Black" StrokeThickness="1.5" Fill="White" Visibility="{Binding DataItem.Visibility}"/> 
</DataTemplate> 

那麼其用於代碼的可視化從我的資源加載它:

... 
line.PointTemplate = (DataTemplate) Application.Current.Resources["PointTemplate"]; 

現在我想的事件處理程序和遊標添加到PointTemplate內的橢圓(= DataTemplate中)。 但是..我該怎麼做?

在此先感謝!

+0

您可以將光標從xaml更改爲'Cursor ='Hand'',並且您要處理什麼事件? –

+0

我想處理MouseDown事件。 將光標設置在xaml中肯定是可能的,但不是所有使用此模板的實例都應該得到它(並且複製模板以使光標複製也不是很好) – Mikk

+0

然後,也許你可以使用類似Trigger或DataTrigger僅在需要時更改光標。 –

回答

1

一對處理事件的方法是使用一個按鈕的命令:

<DataTemplate x:Key="PointTemplate"> 
    <Button Command="Zoom"> 
     <Button.Template> 
      <ControlTemplate> 
       <Ellipse x:Name="Ellipse" Width="80" Height="80" Stroke="Black" StrokeThickness="1.5" Fill="White"/> 
      </ControlTemplate> 
     </Button.Template> 
    </Button> 
</DataTemplate> 

而且你可以在命令添加相應的處理程序。

相關問題