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

Failed to tokenize expression... #7

Open
VashBaldeus opened this issue Jun 20, 2019 · 13 comments
Open

Failed to tokenize expression... #7

VashBaldeus opened this issue Jun 20, 2019 · 13 comments

Comments

@VashBaldeus
Copy link

I am using QuickConverter, and when I use Visiblity for what ever reason I get the following:
Failed to tokenize expression "!$P ? Visibility.Visible : Visibility.Collapsed". Did you forget a '$'?

Tried finding a solution, none so far, anyone has an idea?

@Saeed-Khamseh
Copy link

I think you should include the namespace in which Visibility enum resides to QuickConverter, Otherwise it will not recognize it in an expression. Try to do so by writing this code in your application initialization code:
EquationTokenizer.AddNamespace(typeof(System.Windows.Visibility));

@VashBaldeus
Copy link
Author

VashBaldeus commented Aug 15, 2019

I've actually done that...

    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        public App()
        {
            // Setup Quick Converter.
            QuickConverter.EquationTokenizer.AddNamespace(typeof(object));
            QuickConverter.EquationTokenizer.AddNamespace(typeof(Visibility));
            QuickConverter.EquationTokenizer.AddNamespace(typeof(SolidColorBrush));
            QuickConverter.EquationTokenizer.AddExtensionMethods(typeof(Enumerable));
        }
    }

It only complains about the Visibility Token even though it goes through with Compiling and it works.

@Saeed-Khamseh
Copy link

Saeed-Khamseh commented Aug 15, 2019

Based on the tests that I did, It turned out this expression is only supported by using special binding class on QuickConverter library, not it's converter. The following expression worked successfully for me:

{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed',P={Binding}}

But sounds like you're right and this is not supported:

{Binding Converter={qc:QuickConverter '$P ? Visibility.Visible : Visibility.Collapsed'}}

There's a way to make second expression work which I think is more clean and intelli-sense friendly, and that's by using V0-V9 parameters:

{Binding Converter={qc:QuickConverter '$P ? $V0 : $V1',V0={x:Static Visibility.Visible},V1={x:Static Visibility.Collapsed}}}

@VashBaldeus
Copy link
Author

Based on the tests that I did, It turned out this expression is only supported by using special binding class on QuickConverter library, not it's converter. The following expression worked successfully for me:

{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed',P={Binding}}

But sounds like you're right and this is not supported:

{Binding Converter={qc:QuickConverter '$P ? Visibility.Visible : Visibility.Collapsed'}}

There's a way to make second expression work which I think is more clean and intelli-sense friendly, and that's by using V0-V9 parameters:

{Binding Converter={qc:QuickConverter '$P ? $V0 : $V1',V0={x:Static Visibility.Visible},V1={x:Static Visibility.Collapsed}}}

I actually were using it the entire time as follows:
{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed',P={Binding}}

And that gave me the token issue.

@PanJacky
Copy link

PanJacky commented Nov 5, 2019

I have some issue in "Design Mode" for VS 2017.
when i directly Execute , the qc:Binding Is OK.
I use the qc:Binding in DataTemplate.

<UserControl.Resources>
        <DataTemplate x:Key="FrontDHComboBoxDatatemplate1">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition  Width="40"/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="40"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Content="{Binding Path=DispTrainNo}" HorizontalContentAlignment="Right"/>
                <Label Grid.Column="2" Content="{Binding Path=ArriveTimeString}" Visibility="{qc:Binding '$P == 0  ? Visibility.Collapsed : Visibility.Visible', P={Binding Path=AValue}}"/>
            </Grid>
        </DataTemplate>
</UserControl.Resources>

@Neophear
Copy link

I am having the same issue as @PanJacky. It compiles and runs fine, but the designer tells me that there are errors.

<Button Visibility="{qc:Binding '!$P ? Visibility.Visible : Visibility.Collapsed', P={Binding Path=Editing}}" />
<Button Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding Path=Editing}}" />
<Button Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding Path=Editing}}" />

They are all giving me the same error; Failed to tokenize expression "!$P ? Visibility.Visible : Visibility.Collapsed". Did you forget a '$'?

@gitjsdr26
Copy link

Try this with P0 :
<Button Visibility="{qc:Binding '!$P0 ? Visibility.Visible : Visibility.Collapsed', P0={Binding Path=Editing}}" />

@Neophear
Copy link

@gitjsdr26 Then I get the errors: The member "P0" is not recognized or is not accessible. and The property 'P0' was not found in type 'Binding'.

@gitjsdr26
Copy link

gitjsdr26 commented Aug 21, 2020

@Neophear , nervetheless I'm using this code below that is working and that is similar to yours :

<Button Content="{materialDesign:PackIcon ArrowCompressLeft}" Command="{Binding EnlargeTrackerViewCommand}" Visibility="{qc:MultiBinding '$P0 ? Visibility.Collapsed : Visibility.Visible', P0={Binding IsTrackerEnlarged}}"/>

@ReneVogt
Copy link

I have the same problem as the OP. I have a simple button like this:

<Button Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding IsServerRunning}}"/>

I added the namespaces (tried both: app.xml.cs and mainwindow.xml.cs)

QuickConverter.EquationTokenizer.AddNamespace(typeof(object));
QuickConverter.EquationTokenizer.AddNamespace(typeof(Visibility));

And it works fine for compilation and runtime, but the IDE (VS2019) always shows this error when the designer is open:

Failed to tokenize expression "$P ? Visibility.Collapsed : Visibility.Visible". Did you forget a '$'?

  • QuickConverter v1.2.5
  • Visual Studio 2019 v16.7.7

@gitjsdr26
Copy link

gitjsdr26 commented Nov 24, 2020

Yes, I've also the same problem, but it depends on XAML views. Some does and other none.
VS 16.8.2.

@Xinnony
Copy link

Xinnony commented Sep 12, 2021

Any solution ?, same problem.

@VashBaldeus
Copy link
Author

Any solution ?, same problem.

So far, no solution, does not seem there is one.

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

7 participants