value gone once a converter is used in data binding.
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.
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.
The converter is just a "pass through" for now. here is the code:
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:
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.
Code: Select all
<TextBlock Background="Red" Width="100" Height="40" FontSize="40" Foreground="Green"
Text="{Binding Data.Flood}" RenderTransformOrigin="0.6,1.275" Canvas.Top="45"
/>Now, I added a simple converter.
Code: Select all
<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}}"
/>Code: Select all
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;
}
}Why is this happening? What am I doing wrong?
For reference, this is my rendering code:
Code: Select all
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.
seems you need to convert the resulting value your self when using converters in noesis.
This seems to do the trick:
This seems to do the trick:
Code: Select all
return System.Convert.ChangeType(value, targetType);-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: value gone once a converter is used in data binding.
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.
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.
For some reason I can't login in the Issue Tracker with my forum user.Could you please report it in our bugtracker?
Your account may be disabled or blocked or the username/password you entered is incorrect.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: value gone once a converter is used in data binding.
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 3 guests