C# 自定义控件依赖项属性绑定到属性

C# 自定义控件依赖项属性绑定到属性,c#,wpf,silverlight,custom-controls,dependency-properties,C#,Wpf,Silverlight,Custom Controls,Dependency Properties,只是玩弄不同类型的绑定,让一个属性将自定义控件的依赖属性绑定到另一个属性 XAML: 在MainWindow.xaml中实现 <UserControl x:Class="BrickBreaker.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://sc

只是玩弄不同类型的绑定,让一个属性将自定义控件的依赖属性绑定到另一个属性

XAML:

在MainWindow.xaml中实现

<UserControl x:Class="BrickBreaker.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:BrickBreaker="clr-namespace:BrickBreaker" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
    <BrickBreaker:Brick Margin="100,100,0,0" BrickFill="Azure"/>
</Grid>

基本上,我想将矩形填充属性绑定到代码隐藏中的依赖项属性

谢谢


史蒂夫

确切的问题是什么?将UserControl的DataContext设置为代码隐藏,例如:

<UserControl DataContext="{Binding RelativeSource={RelativeSource Self}}">

</UserControl>

确切的问题是什么?将UserControl的DataContext设置为代码隐藏,例如:

<UserControl DataContext="{Binding RelativeSource={RelativeSource Self}}">

</UserControl>

缺少这个:DataContext=“{Binding RelativeSource={RelativeSource Self}}”

缺少这个:DataContext=“{Binding RelativeSource={RelativeSource Self}”

<UserControl DataContext="{Binding RelativeSource={RelativeSource Self}}">

</UserControl>