我有一个用户控件,它试图绑定父控件的文本框,
文本块控件.xaml
<UserControl x:Class="wpf_sandbox.TextBlockControl"
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"
mc:Ignorable="d" >
<Grid>
<TextBlock Text="{Binding Text, ElementName=editor}"></TextBlock>
</Grid>
</UserControl>
主窗口.xaml
<Window x:Class="wpf_sandbox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wpfSandbox="clr- namespace:wpf_sandbox"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBox x:Name="editor"></TextBox>
<wpfSandbox:TextBlockControl></wpfSandbox:TextBlockControl>
</StackPanel>
</Window>
这根本行不通。我尝试了几种方法,例如使用相对源和源,但也没有奏效。