2017-06-22 6 views
0

私は新しいUserControlTextBox)を作成しようとしていますが、すべてのテキストが選択されていますが、コードから.textを更新できません。私が達成しようとしている何カスタムのusercontrol textbox.text

は次のとおりです。

<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> 

Public Class SelectAllTbox 
Private Sub textBox_GotFocus(sender As Object, e As RoutedEventArgs) Handles textBox.GotFocus 
    textBox.SelectAll() 

End Sub 
End Class  

そして、これは私のコード内のコントロールです:

kolicinaTbox.text = "test" 

私のカスタムコントロールがある

<demo:SelectAllTbox x:Name="kolicinaTbox" HorizontalAlignment="Left" Margin="82,152,0,0" VerticalAlignment="Top" Width="63"/> 

答えて

1

取得/ TextBoxTextプロパティが設定されますあなたのUserControlSelectAllTboxクラス)にプロパティを追加します。

Public Property Text() As String 
    Get 
     Return textBox.Text 
    End Get 
    Set(ByVal value As String) 
     textBox.Text = value 
    End Set 
End Property 

その後、このプロパティを使用してTextBoxTextプロパティを設定することができます。

kolicinaTbox.Text = "test" 
関連する問題