C# 从父控件绑定到子属性

C# 从父控件绑定到子属性,c#,wpf,C#,Wpf,我有一个用户控件: <UserControl x:Class="WpfApplication2.Control1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.o

我有一个用户控件:

<UserControl x:Class="WpfApplication2.Control1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:WpfApplication2"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>
    <StackPanel Orientation="Horizontal" Name="StackPanelInsideUserControl">
        <Label />
        <TextBox Name="TextBoxInsideUserControl" Text="Initial Text" />
        <Button Content="OK" />
    </StackPanel>
</Grid>

我正试图从其父级绑定TextBoxInsideUserControl TextBox的Text属性,如:

<Window x:Class="WpfApplication2.MainWindow"
    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:local="clr-namespace:WpfApplication2"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <local:Control1 StackPanelInsideUserControl.TextBoxInsideUserControl.Text="{Binding SomeText}" />
</Grid>


我怎样才能做到这一点?xaml允许我们这样做吗?

根据要求,评论作为回答:


不,不是真的。您应该在该
UserControl
上定义一个依赖项属性,并将其绑定到
文本框的文本。然后,您可以通过该依赖属性访问UserControl之外的文本。

不,不太可能。您应该在该UserControl上定义依赖项属性,并将其绑定到TextBox的文本。然后,您可以通过该依赖属性访问UserControl之外的文本。感谢您指出这一点。我正在使用第三方框架代替用户控件,我会请求他们的支持。但现在我知道了xaml的方法。介意把这个贴出来作为答案吗?然后我可以标记并给你学分?