JohannesMoersch / QuickConverter

QuickConverter provides you with WPF markup that allows you to write inline converters, multi-bindings, and event handlers using a C# like language directly in your xaml.
MIT License
110 stars 13 forks source link

Failed to tokenize expression... #7

Open VashBaldeus opened 5 years ago

VashBaldeus commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

Neophear commented 4 years ago

@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 commented 4 years ago

@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 commented 3 years ago

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 '$'?

gitjsdr26 commented 3 years ago

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

Xinnony commented 3 years ago

Any solution ?, same problem.

VashBaldeus commented 2 years ago

Any solution ?, same problem.

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