我创建了一个名为 UserControlUserControl1
并将其添加到我的MainWindow中。
我想要的是,当用户单击add
UserControl 上的按钮时, MainWindowdata
中调用的标签的内容发生了变化。
<UserControl x:Class="WpfApplication6.UserControl1"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Content="add" x:Name="add"/>
</Grid>
</UserControl>
<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfApplication6="clr-namespace:WpfApplication6"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation="Vertical">
<Label Content="data" x:Name="data"/>
<WpfApplication6:UserControl1 x:Name="myUC"/>
</StackPanel>
</Grid>
</Window>
我怎样才能做到这一点 ?