Open VashBaldeus opened 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));
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.
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}}}
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.
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>
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 '$'?
Try this with P0
:
<Button Visibility="{qc:Binding '!$P0 ? Visibility.Visible : Visibility.Collapsed', P0={Binding Path=Editing}}" />
@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'.
@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}}"/>
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 '$'?
Yes, I've also the same problem, but it depends on XAML views. Some does and other none. VS 16.8.2.
Any solution ?, same problem.
Any solution ?, same problem.
So far, no solution, does not seem there is one.
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?