Page 1 of 1

value gone once a converter is used in data binding.

Posted: 17 Dec 2018, 11:09
by Elad8a
I wrote a small code based on the Noesis IntegrationSharpDX sample.

My goal is to render a 2D UI to on top of an existing Direct3D11 scene. No user interaction via keyboard or mouse is needed with the UI, I only need Noesis for rendering 2D symbology.

I created a user control (C#) and within it another UserControl. in the inner UserControl, I have a simple TextBox with its text property bound a view model value.
     <TextBlock Background="Red" Width="100" Height="40" FontSize="40" Foreground="Green"                         
                           Text="{Binding Data.Flood}" RenderTransformOrigin="0.6,1.275" Canvas.Top="45"                       
                           />
With this, everything works as planned. once I update the viewmodel value, I can see the TextBlock text change on the d3d texture.

Now, I added a simple converter.
        <Grid.Resources>
            <local:SampleConverter x:Key="converter"/>
        </Grid.Resources>
...

            <TextBlock Background="Red" Width="100" Height="40" FontSize="40" Foreground="Green"                         
                           Text="{Binding Data.Flood, Converter={StaticResource converter}}"                       
                           />
The converter is just a "pass through" for now. here is the code:
using Noesis;

    internal class SampleConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }

        public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
Now, the value on the TextBlock won't appear. although I can see the converter methods hit on the debugger with the correct value once it is changed.



Why is this happening? What am I doing wrong?



For reference, this is my rendering code:
        public void Render()
        {
            Update(); // in the future, will be called from ui thread

            _d3d11Device.ImmediateContext.Rasterizer.SetViewport(new Viewport(0, 0, ProgramGlobals.OFFSCREEN_BUFFER_PIXEL_WIDTH, ProgramGlobals.OFFSCREEN_BUFFER_PIXEL_HEIGHT));
            _d3d11Device.ImmediateContext.OutputMerger.SetTargets(_depthStencilView, _renderTargetView);
            _d3d11Device.ImmediateContext.ClearRenderTargetView(_renderTargetView, CLEAR_COLOR);
            _d3d11Device.ImmediateContext.ClearDepthStencilView(_depthStencilView, DepthStencilClearFlags.Stencil, 0.0f, 0);

            // apply last changes from the view to the render state 

            _d3dState.Save(_d3d11Device.ImmediateContext);

            _renderer.UpdateRenderTree();

            if (_renderer.NeedsOffscreen())
            {
                _renderer.RenderOffscreen();
            }

            _d3dState.Restore(_d3d11Device.ImmediateContext);

            _d3dState.Save(_d3d11Device.ImmediateContext);
            _renderer.Render();
            _d3dState.Restore(_d3d11Device.ImmediateContext);

            // present
            _d3d11Device.ImmediateContext.Flush(); 
        }

Re: value gone once a converter is used in data binding.

Posted: 17 Dec 2018, 11:41
by Elad8a
seems you need to convert the resulting value your self when using converters in noesis.

This seems to do the trick:
         return System.Convert.ChangeType(value, targetType);

Re: value gone once a converter is used in data binding.

Posted: 17 Dec 2018, 12:44
by sfernandez
Hi, thank for reporting and sharing the solution.

Anyway, I found that in WPF you can return in your converter the original value type and it gets converted internally by the binding if there is a default converter capable of converting between source and target types. Could you please report it in our bugtracker?

You can use the solution you found in the meantime.

Re: value gone once a converter is used in data binding.

Posted: 20 Dec 2018, 08:07
by Elad8a
Could you please report it in our bugtracker?
For some reason I can't login in the Issue Tracker with my forum user.
Your account may be disabled or blocked or the username/password you entered is incorrect.

Re: value gone once a converter is used in data binding.

Posted: 20 Dec 2018, 09:53
by sfernandez
Forums and Bugtracker use independent login credentials, you'll have to create a new account for the bugtracker (you can use the same username and email to register if you want).