benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.71k stars 143 forks source link

Binding errors when using ComboBox #18

Closed nkristek closed 5 years ago

nkristek commented 5 years ago

I noticed, that the application output is filled with messages, that a BindingExpression path error occured, when using a ComboBox:

System.Windows.Data Error: 40 : BindingExpression path error: '(adonisExtensions:WatermarkExtension.IsWatermarkVisible)' property not found on 'object' ''ComboBox' (Name='')'. BindingExpression:Path=(adonisExtensions:WatermarkExtension.IsWatermarkVisible); DataItem='ComboBox' (Name=''); target element is 'TextBox' (Name='PART_EditableTextBox'); target property is 'NoTarget' (type 'Object')
Exception thrown: 'MS.Internal.Xaml.Parser.GenericTypeNameParser.TypeNameParserException' in System.Xaml.dll
System.Windows.Data Error: 40 : BindingExpression path error: '(adonisExtensions:WatermarkExtension.Watermark)' property not found on 'object' ''ComboBox' (Name='')'. BindingExpression:Path=(adonisExtensions:WatermarkExtension.Watermark); DataItem='ComboBox' (Name=''); target element is 'ContentPresenter' (Name='PlaceholderHost'); target property is 'Content' (type 'Object')
Exception thrown: 'MS.Internal.Xaml.Parser.GenericTypeNameParser.TypeNameParserException' in System.Xaml.dll

These two errors occur for every ComboBox in my view. I'm using the latest version of AdonisUI (1.9), I haven't noticed this with earlier versions but I have not tested it specifically with other versions of AdonisUI. This is the view, the error occurs, the following code snippet is the ComboBox in the view:

<ComboBox Grid.Column="0"
          ItemsSource="{Binding InstallerBundles}"
          SelectedItem="{Binding SelectedInstallerBundle}"
          HorizontalContentAlignment="Stretch"
          ScrollViewer.CanContentScroll="True"
          VirtualizingStackPanel.IsVirtualizing="True"
          VirtualizingStackPanel.VirtualizationMode="Recycling"
          VirtualizingStackPanel.ScrollUnit="Pixel">

    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate >
            <VirtualizingStackPanel/>
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
</ComboBox>

The view for an installer bundle consists of only a single TextBox:

<TextBlock TextTrimming="CharacterEllipsis"
           Text="{Binding Name}"/>

There seems to be no error while using the application, I just wanted to check, if the errors can be ignored.

benruehl commented 5 years ago

I cannot reproduce this behavior with ComboBoxes but I get similar output for TabControls.

I found this blog post stating that they are harmless and handled internally. It seems the error can occur for all controls that contain dynamically created lists.

To resolve the binding errors you could try to explicitly set the watermark to {x:Null} or an empty string. As I cannot reproduce it, I cannot test that for you. Alternatively you can change the log level globally as shown here.

benruehl commented 5 years ago

Oh wait I just noticed that you received BindingError 40 and I get BindingError 4. My answer was supposed to target BindingError 4. I will do some research again but as I cannot reproduce it, it will be hard to tackle.

benruehl commented 5 years ago

I created a small application where I tried to recreate your setup and finally got the errors as well.

Writing

<DataTrigger Binding="{Binding Path=(adonisExtensions:WatermarkExtension.IsWatermarkVisible)}"/>

instead of

<DataTrigger Binding="{Binding (adonisExtensions:WatermarkExtension.IsWatermarkVisible)}"/>

fixed it for me.

Please reopen in case the errors are still present in your application.