0

so I have an Textbox on which I binded an Property that is named: Artikelnummer

In the Property of Artikelnummer I have some code in the set part, but after my code I want to select the whole Text of the Textbox where the Property is Binded to.

How can I select the text of the Textbox from the ViewModel binded Property?

Like I have this Textbox:

 <TextBox x:Name="txtReferenzartikelnummer" Grid.Column="1" Style="{StaticResource WatermarkErrorTooltip}"  HorizontalAlignment="Stretch" 
                                         Height="32" TextWrapping="Wrap" Tag="Artikelnummer" VerticalAlignment="Center" Margin="0,0,31,0" Text="{Binding Artikelnummer}
                                         KeyUp="txtWechselEnter_KeyUP"/>

string _Artikelnummer;

    public string Artikelnummer
    {
        get { return _Artikelnummer; }
        set
        {
            _Artikelnummer = value;
            
        //my code

        //here it should selectAll text of the Textbox

        }
    }`

Anyone an Idea?

  • `value` has the entire text that is being sent from `TextBox`. – XAMlMAX Feb 27 '23 at 10:59
  • yeah I know, but I want in the Property to select the text of the textbox – BeginnerWPF Feb 27 '23 at 11:13
  • You could use a behaviour for that. [Here](https://stackoverflow.com/a/1264633/2029607) is a link that will show you how to use behaviours and you can modify it to suit your needs. – XAMlMAX Feb 27 '23 at 11:57
  • You need to do the selection in the view and that can be driven by handling OnTargetUpdated https://learn.microsoft.com/en-us/dotnet/api/system.windows.data.binding.notifyontargetupdated?view=windowsdesktop-7.0 – Andy Feb 27 '23 at 13:10
  • @BeginnerWPF: A source property is not supposed to select text in a view. – mm8 Mar 01 '23 at 14:33

0 Answers0