Uwp UserControl中的绑定问题

Uwp UserControl中的绑定问题,uwp,uwp-xaml,Uwp,Uwp Xaml,我正试图实现一些应该很简单的事情,但我被卡住了 我想做的是:一个用户控件,它只是边界前面的一个图标 这里是我的UC的xaml <UserControl x:Class="Project.Views.UC.UC_CircledIcons" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:l

我正试图实现一些应该很简单的事情,但我被卡住了

我想做的是:一个用户控件,它只是边界前面的一个图标

这里是我的UC的xaml

<UserControl
x:Class="Project.Views.UC.UC_CircledIcons"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Project.Views.UC"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:fa="using:FontAwesome5.UWP"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
d:DesignHeight="200"
d:DesignWidth="200">
<Border Style="{StaticResource BorderStyle1}"  Height="{Binding Height}" Width="{Binding Width}" BorderBrush="{Binding MyColor}" VerticalAlignment="Center" HorizontalAlignment="Center">
    <fa:FontAwesome Foreground="{Binding MyColor}" Icon="{Binding MyIcon}" Height="{Binding Height}" Width="{Binding Width}" FontSize="{Binding MyFontSize}" VerticalAlignment="Center" HorizontalAlignment="Center"></fa:FontAwesome>
</Border>
在我的UserControl代码中。似乎xaml正在我的USerControl定义中查找名为MainIcon的属性,或者该属性是我的ViewModel的一部分

我在哪里遗漏了什么?有没有办法实现我的目标?非常感谢您的帮助。

DataContext=“{Binding RelativeSource={RelativeSource Self}}}”替换为
Name=“uc”
,并使用
ElementName
绑定到属性:

<Border ... BorderBrush="{Binding MyColor, ElementName=uc}" ... />


然后,
UserControl
应该像预期的那样继承它的
DataContext
,但是您仍然能够在它的XAML标记中绑定到控件本身的属性。

它完成了任务。谢谢!
<uc:UC_CircledIcons MyColor="#321654" MyIcon="Solid_Check"></uc:UC_CircledIcons>
<uc:UC_CircledIcons MyColor="{Binding MainIconColor}" MyIcon="{Binding MainIcon}"></uc:UC_CircledIcons>
DataContext="{Binding RelativeSource={RelativeSource Self}}"
<Border ... BorderBrush="{Binding MyColor, ElementName=uc}" ... />