unoplatform / Uno.WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helper functions, custom controls, and app services. It simplifies and demonstrates common developer tasks building UWP apps for Windows 10. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/uwpcommunitytoolkit/
Other
61 stars 11 forks source link

TextBoxRegex doesn't work within a TabViewItem #75

Open FrancoisM opened 4 years ago

FrancoisM commented 4 years ago

this alone in a page works:

<StackPanel>
                    <TextBox Header="Nom" Text="{Binding Nom, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                         extensions:TextBoxRegex.Regex="{x:Bind NomRegex}"
                         extensions:TextBoxRegex.ValidationMode="Forced" 
                         Background="{Binding (extensions:TextBoxRegex.IsValid), RelativeSource={RelativeSource Self}, Converter={StaticResource ValidationConverter}}"
                         Style="{StaticResource InputStyle}"/>
                    <Button Content="OK"/>
                </StackPanel>

but put into a TabViewItem and the TextBoxRegex stops working:

<custom:TabView>
        <custom:TabView.Items>
            <custom:TabViewItem Header="Info">
                <StackPanel>
                    <TextBox Header="Nom" Text="{Binding Nom, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                         extensions:TextBoxRegex.Regex="{x:Bind NomRegex}"
                         extensions:TextBoxRegex.ValidationMode="Forced" 
                         Background="{Binding (extensions:TextBoxRegex.IsValid), RelativeSource={RelativeSource Self}, Converter={StaticResource ValidationConverter}}"
                         Style="{StaticResource InputStyle}"/>
                    <Button Content="OK"/>
                </StackPanel>
            </custom:TabViewItem>
        </custom:TabView.Items>
    </custom:TabView>

with:

public class ValidationConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language) => (bool)value ? new SolidColorBrush(Colors.PaleGreen) : new SolidColorBrush(Colors.OrangeRed);
        public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException();
    }

private string NomRegex { get; } ="^.{2,}$";

FrancoisM commented 4 years ago

Note: the following does work as well so the issue is not with RelativeSource={RelativeSource Self}:

<custom:TabView>
        <custom:TabView.Items>
            <custom:TabViewItem Header="Info">
                <StackPanel>
                    <TextBox Header="Nom" Text="{Binding Nom, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Background="{Binding Text, RelativeSource={RelativeSource Self}, Converter={StaticResource TestConverter}}"/>
                    <Button Content="OK"/>
                </StackPanel>
            </custom:TabViewItem>
        </custom:TabView.Items>
    </custom:TabView>
public class TestConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language) => ((string)value).Length >2 ? new SolidColorBrush(Colors.PaleGreen) : new SolidColorBrush(Colors.OrangeRed);
        public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException();
    }
jeromelaban commented 4 years ago

Thanks! On which platform do you see this behavior ?

FrancoisM commented 4 years ago

Sorry, forgot to mention it's on wasm.