Windows icon indicating copy to clipboard operation
Windows copied to clipboard

Can't set Text Property programmatically

Open OZ1 opened this issue 2 years ago • 6 comments

Describe the bug

When I set .Text in code, the property changes it's value, but this text doesn't appear in the TextBox.

<Window
	x:Class="TokenizingTextBox_Text_BUG.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:controls="using:CommunityToolkit.WinUI.UI.Controls"
	mc:Ignorable="d">

	<controls:TokenizingTextBox ItemClick="TokenizingTextBox_ItemClick"
		PlaceholderText="Add and click token to set the Text property" />
</Window>
using CommunityToolkit.WinUI.UI.Controls;

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace TokenizingTextBox_Text_BUG;

sealed partial class MainWindow : Window
{
	public MainWindow() => InitializeComponent();

	void TokenizingTextBox_ItemClick(object sender, ItemClickEventArgs e)
	{
		if (sender is TokenizingTextBox tokenBox)
			tokenBox.Text = (string)e.ClickedItem;
	}
}

TokenizingTextBox Text.zip

Steps to reproduce

#
tokenBox.Text = "some value";

Expected behavior

Text appears in the text box.

Screenshots

No response

Code Platform

  • [ ] UWP
  • [X] WinAppSDK / WinUI 3
  • [ ] Web Assembly (WASM)
  • [ ] Android
  • [ ] iOS
  • [ ] MacOS
  • [ ] Linux / GTK

Windows Build Number

  • [ ] Windows 10 1809 (Build 17763)
  • [ ] Windows 10 1903 (Build 18362)
  • [ ] Windows 10 1909 (Build 18363)
  • [ ] Windows 10 2004 (Build 19041)
  • [ ] Windows 10 20H2 (Build 19042)
  • [ ] Windows 10 21H1 (Build 19043)
  • [ ] Windows 10 21H2 (Build 19044)
  • [X] Windows 10 22H2 (Build 19045)
  • [ ] Windows 11 21H2 (Build 22000)
  • [ ] Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • [ ] Windows 10, version 1809 (Build 17763)
  • [ ] Windows 10, version 1903 (Build 18362)
  • [ ] Windows 10, version 1909 (Build 18363)
  • [ ] Windows 10, version 2004 (Build 19041)
  • [ ] Windows 10, version 2104 (Build 20348)
  • [ ] Windows 11, version 22H2 (Build 22000)
  • [ ] Other (specify)

Other SDK version

No response

Visual Studio Version

No response

Visual Studio Build Number

17.9.0 Preview 2.0

Device form factor

Desktop

Additional context

No response

Help us help you

Yes, but only if others can assist.

OZ1 avatar Dec 22 '23 22:12 OZ1

Shouldn't there be a x:Name="tokenBox" in the xaml?

Jay-o-Way avatar Jan 02 '24 01:01 Jay-o-Way

Shouldn't there be a x:Name="tokenBox" in the xaml?

It is not necessary, we get it from the sender argument in the example

OZ1 avatar Jan 02 '24 08:01 OZ1

The version 8.0 works fine.

OZ1 avatar Jan 08 '24 02:01 OZ1

@OZ1 yes, I believe this was a bug we fixed between versions. Can I close this issue now then?

michael-hawker avatar Jan 09 '24 22:01 michael-hawker

Links here should be updated to point to the working version. Now it points to 7.10

OZ1 avatar Jan 11 '24 18:01 OZ1

When the links are up to date, I think it should be closed.

OZ1 avatar Jan 11 '24 18:01 OZ1