Elad8a
Topic Author
Posts: 6
Joined: 17 Jun 2018, 20:52

value gone once a converter is used in data binding.

17 Dec 2018, 11:09

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(); 
        }

Tags:
 
Elad8a
Topic Author
Posts: 6
Joined: 17 Jun 2018, 20:52

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

17 Dec 2018, 11:41

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);
 
User avatar
sfernandez
Site Admin
Posts: 1451
Joined: 22 Dec 2011, 19:20

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

17 Dec 2018, 12:44

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.
 
Elad8a
Topic Author
Posts: 6
Joined: 17 Jun 2018, 20:52

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

20 Dec 2018, 08:07

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.
 
User avatar
sfernandez
Site Admin
Posts: 1451
Joined: 22 Dec 2011, 19:20

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

20 Dec 2018, 09:53

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).

Who is online

Users browsing this forum: No registered users and 2 guests