0
我的工作與WPF MVVMClick事件右擊事件數據綁定模板
我做了如下DataTemplate
:
<DataTemplate DataType="{x:Type r:CustomControl}">
<Border x:Name="bord" BorderThickness="0" Width="150" Height="150" Margin="0"
BorderBrush="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Background}"
Background="{Binding RelativeSource={RelativeSource AncestorType={x:Type con:Control}, Mode=FindAncestor}, Path=TileColorPair[0]}"
ContextMenu="{StaticResource CMenu}">
<Button Width="{Binding Size}" Height="{Binding Size}">
<Button.Template>
<ControlTemplate>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image x:Name="img" Grid.Row="0" Source="{Binding ImageUrl}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Label Grid.Row="1" Content="{Binding Text}" FontFamily="{DynamicResource DefaultFont}" FontSize="{DynamicResource {x:Static SystemFonts.CaptionFontSizeKey}}"
Foreground="White" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
</Border>
我在Border
相關的ContextMenu
。 每個菜單都有一個特定的Command
。
<ContextMenu x:Key="CMenu">
<MenuItem Command="{Binding UpdateCommand}" Header="Update">
<MenuItem.Icon>
<Image Width="45" Height="45" Source="/Assembly;component/Resources/edit.png"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="{Binding SelectCommand}" Header="Select">
<MenuItem.Icon>
<Image Width="45" Height="45" Source="/Assembly;component/Resources/search.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
如何綁定從右鍵激活的ContextMenu
的左鍵以及事件?
什麼是Source = Win' @Chris? – Darknesstiller
@Darknesstiller;它是'Border'元素的名稱。就我而言,「贏」。您可以將其設置爲「Source = sender」 –