value gone once a converter is used in data binding.
Posted: 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.
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();
}