2011-11-02 47 views
0

我有风情的菜单项:菜单项风格的图像

<Style x:Key="mainMenuItem" 
     TargetType="{x:Type Resources:MainMenuItem}"> 
</Style> 

我怎样才能设置图标属性TemplateBinding的ImageSource? 我有MainMenuItem.cs:

public class MainMenuItem : MenuItem 
{ 
    public static readonly DependencyProperty ImageSourceProperty = 
           DependencyProperty.Register(
               "ImageSource", 
               typeof (ImageSource), 
               typeof (MainMenuItem), 
               new UIPropertyMetadata(null)); 

    public ImageSource ImageSource 
    { 
     get { return (ImageSource) GetValue(ImageSourceProperty); } 
     set { SetValue(ImageSourceProperty, value); } 
    } 
} 

回答

1

你可以只完全忽略Icon财产,并为Template一个Setter您在其中具有模板结合ImageSource前面定义Image,或者你可以注册依赖项属性更改了ImageSource上的回调,其中您创建了Image并将其设置为Icon