如何在wpf usercontrol中将数据绑定属性设置为textblock?
给出错误和设计视图的XAML变得不可见 请帮忙。我想你需要帮助 用户控制示例如何在wpf usercontrol中将数据绑定属性设置为textblock?,wpf,data-binding,Wpf,Data Binding,给出错误和设计视图的XAML变得不可见 请帮忙。我想你需要帮助 用户控制示例 Text="{Binding ClickCount1, ElementName=myusercontrol, Mode=Default} 使用带绑定的用户控件的窗口示例 <UserControl x:Class="WpfApplication1.myusercontrol" xmlns="http://schemas.microsoft.com/winfx/2006/xam
Text="{Binding ClickCount1, ElementName=myusercontrol, Mode=Default}
使用带绑定的用户控件的窗口示例
<UserControl x:Class="WpfApplication1.myusercontrol"
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:WpfApplication1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock Name="ClickCount1" Text="12" />
</Grid>
</UserControl>
是否存在名为myusercontrol
的UserControl
用户控件?是。我已经将usercontrol即“myusercontrol”装箱,这显示了什么?Text=“{Binding ElementName=myusercontrol,Mode=Default}
?简单地说,在C#中,我们为控件设置文本,比如Ctrl,Text=“data”"; 像这样,我如何设置文本块控件的文本…绑定中的ClickCount1
是什么?谢谢。而且效果很好。由于我的个人资料的声望很低,我无法回答这个问题。
<UserControl x:Class="WpfApplication1.myusercontrol"
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:WpfApplication1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock Name="ClickCount1" Text="12" />
</Grid>
</UserControl>
<Window x:Class="WpfApplication1.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:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<local:myusercontrol x:Name="MyUserControl" />
<TextBlock Grid.Row="1" Text="{Binding ElementName=MyUserControl.ClickCount1, Path=Text}" />
</Grid>
</Window>