Open
Description
Describe the bug
Upon loading a TokenizedTextBox control in an App SDK packaged or unpackaged project, when using localized properties, the following exception is thrown:
- Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work: 7.1.1 (UWP)
Steps to Reproduce
- Can this be reproduced in the Sample App? (Either in a sample as-is or with new XAML pasted in the editor.) If so, please provide custom XAML or steps to reproduce. If not, let us know why it can't be reproduced (e.g. more complex setup, environment, dependencies, etc...)
No sample app is available for App SDK preview 3 as far as I'm aware so I cannot test it here.
Steps to reproduce the behavior:
- Create a new AppSDK preview 3 packaged project with WinUI 3
- Add a reference to the CommunityToolkit 7.1.1-preview3
- Add the following xaml in mainwindow.xaml:
<Window
x:Class="App1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ctk="using:CommunityToolkit.WinUI.UI.Controls"
mc:Ignorable="d">
<ctk:TokenizingTextBox Margin="0,4"
CornerRadius="8"
ItemsSource="{x:Bind TestCollection, Mode=TwoWay}"
PlaceholderText="{local:ResourceString Name=TestPlaceholder}"
TokenDelimiter=";" />
</Window>
- Add the following code in mainwindow.xaml.cs
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.ApplicationModel.Resources;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace App1
{
public static class ResourceStringHelper
{
/// <summary>
/// Gets the following resource string from the application resx files
/// This method cannot be called from any thread.
/// </summary>
/// <param name="id">The identifier of the resource string</param>
/// <returns></returns>
public static string GetStringFromResources(string id)
{
ResourceLoader resourceLoader = new ResourceLoader();
return resourceLoader.GetString(id);
}
}
[MarkupExtensionReturnType(ReturnType = typeof(string))]
public sealed class ResourceString : MarkupExtension
{
public string Name
{
get; set;
}
protected override object ProvideValue()
{
return ResourceStringHelper.GetStringFromResources(Name);
}
}
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
public ObservableCollection<string> TestCollection = new();
public MainWindow()
{
this.InitializeComponent();
}
}
}
- Add a new Resources.resw, in Strings\en\Resources.resw, with a single key/value pair: "TestPlaceholder" => "I'm a test"
- In configuration manager, tick the deploy checkbox so visual studio deploys the application
- Run the application
- An exception is thrown
Expected behavior
The control should load and work properly without an exception being thrown.
Environment
NuGet Package(s):
- CommunityToolkit.WinUI.UI.Controls
- Microsoft.WindowsAppSDK (1.0.0-preview3)
- Microsoft.Windows.SDK.BuildTools (10.0.20348.19)
Package Version(s):
7.1.1-preview3
Windows 10 Build Number:
- Fall Creators Update (16299)
- April 2018 Update (17134)
- October 2018 Update (17763)
- May 2019 Update (18362)
- May 2020 Update (19041)
- Insider Build (22000.282)
App min and target version:
- Fall Creators Update (16299)
- April 2018 Update (17134)
- October 2018 Update (17763)
- May 2019 Update (18362)
- May 2020 Update (19041)
Device form factor:
- Desktop
- Xbox
- Surface Hub
- IoT
Visual Studio version:
- 2022 (17.Preview/17.0.0-pre.7.0+31825.309)
Additional context
The control works fine without the localized string, removing it makes it work. However the issue is not the local:ResourceString markup extension as using it in a textblock works fine, as such:
<Window
x:Class="App1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ctk="using:CommunityToolkit.WinUI.UI.Controls"
mc:Ignorable="d">
<TextBlock Text="{local:ResourceString Name=TestPlaceholder}"/>
</Window>