Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextBoxRegex doesn't work within a TabViewItem #75

Open
FrancoisM opened this issue Jan 16, 2020 · 3 comments
Open

TextBoxRegex doesn't work within a TabViewItem #75

FrancoisM opened this issue Jan 16, 2020 · 3 comments

Comments

@FrancoisM
Copy link

FrancoisM commented Jan 16, 2020

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
Copy link
Author

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
Copy link
Member

Thanks! On which platform do you see this behavior ?

@FrancoisM
Copy link
Author

Sorry, forgot to mention it's on wasm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants