Wpf 自定义用户控件textbox.text
我正在尝试创建一个新的Wpf 自定义用户控件textbox.text,wpf,vb.net,Wpf,Vb.net,我正在尝试创建一个新的UserControl(TextBox,它选择焦点上的所有文本),但我无法从代码中更新.text 我想要实现的是: kolicinaTbox.text = "test" 我的自定义控件是: <UserControl x:Class="SelectAllTbox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sch
UserControl
(TextBox
,它选择焦点上的所有文本),但我无法从代码中更新.text
我想要实现的是:
kolicinaTbox.text = "test"
我的自定义控件是:
<UserControl x:Class="SelectAllTbox"
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:Demo"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="120"/>
</Grid>
这是我代码中的控件:
<demo:SelectAllTbox x:Name="kolicinaTbox" HorizontalAlignment="Left" Margin="82,152,0,0" VerticalAlignment="Top" Width="63"/>
向
用户控件添加一个属性(SelectAllTbox
类),该属性获取/设置文本框的文本属性:
Public Property Text() As String
Get
Return textBox.Text
End Get
Set(ByVal value As String)
textBox.Text = value
End Set
End Property
然后,您可以使用此属性设置文本框的Text
属性:
kolicinaTbox.Text = "test"
kolicinaTbox.Text = "test"