C# 短装订

C# 短装订,c#,wpf,C#,Wpf,我真的不明白为什么我不能喜欢它: <Label Content="{Binding SomeObiect}"/> 没有人回答我的问题。。。 但你们中的许多人给了我一个负-- 我不知道这是否符合标准,但我很喜欢: <Grid DataContext="{Binding ElementName=btn_Skill}"> <Viewbox> <Image Source="{Binding BackgroundImageSou

我真的不明白为什么我不能喜欢它:

<Label Content="{Binding SomeObiect}"/>

没有人回答我的问题。。。 但你们中的许多人给了我一个负--

我不知道这是否符合标准,但我很喜欢:

<Grid DataContext="{Binding ElementName=btn_Skill}">     
    <Viewbox>
        <Image Source="{Binding BackgroundImageSource}"/>
    </Viewbox>
</Grid>
该绑定更改了所有子项的DataContext,因此我不需要在所有Bingins中重写它

public partial class SkillButton : UserControl
{
    [...]

    public static readonly DependencyProperty BackgroundImageSourceProperty = DependencyProperty.Register("BackgroundImageSource", typeof(ImageSource), typeof(SkillButton));
    public ImageSource BackgroundImageSource
    {
        get { return (ImageSource)GetValue(BackgroundImageSourceProperty); }
        set { SetValue(BackgroundImageSourceProperty, value); }
    }
}
<Grid DataContext="{Binding ElementName=btn_Skill}">     
    <Viewbox>
        <Image Source="{Binding BackgroundImageSource}"/>
    </Viewbox>
</Grid>