chaiwarat@gmail.com
Topic Author
Posts: 3
Joined: 08 Jun 2017, 03:24

need d3d11 sample with MVVM and code behind

12 Jun 2017, 01:37

Dear support team,

The d3d11 sample project is working.
But, I need more sample in using code behind and mvvm binding in this project to learn how to integrate and use them.
Please help.

Thank you.
Chaiwarat
 
User avatar
jsantos
Site Admin
Posts: 2908
Joined: 20 Jan 2012, 17:18
Contact:

Re: need d3d11 sample with MVVM and code behind

12 Jun 2017, 12:26

We are working to provide more samples directly in the C++ SDK. Just ready for opening the solution and compiling.

But for now, you can find code for MVVM in the Data Binding and Commands tutorials.
 
chaiwarat@gmail.com
Topic Author
Posts: 3
Joined: 08 Jun 2017, 03:24

Re: need d3d11 sample with MVVM and code behind

13 Jun 2017, 01:26

Dear support,

I was talking about the d3d11 sample project bundled with the Noesis package.
It was written in c# and run without Unity 3D.
In the code, it just load the style xaml and the layout xaml. So, I wonder how to integrate the code behind and view model in to this kind of environment.

{
var theme = (Noesis.ResourceDictionary)Noesis.GUI.LoadXaml("NoesisStyle.xaml");
Noesis.GUI.SetTheme(theme);
}

// Data loading
{
var content = (Noesis.Grid)Noesis.GUI.LoadXaml("TextBox.xaml");
view = Noesis.GUI.CreateView(content);

var immediateContext = dxWrapper.Device.ImmediateContext;
renderer = view.Renderer;
renderer.InitD3D11(immediateContext.NativePointer, new Noesis.VGOptions());
}

Thank you.
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: need d3d11 sample with MVVM and code behind

13 Jun 2017, 16:53

Hi,

You can attach any view model to the loaded content. For example, imagine the TextBox.xaml sample has a binding like this:
<TextBox Text="{Binding SampleText}" .../>
Then you can define a class exposing that property:
public class SampleViewModel
{
  public string SampleText { get; set; }
}
And attach it to the data context of the root element:
// Data loading
{
var content = (Noesis.Grid)Noesis.GUI.LoadXaml("TextBox.xaml");
content.DataContext = new SampleViewModel { SampleText = "This is a test" };
view = Noesis.GUI.CreateView(content);
//...
}
This will show the text "This is a test" in the TextBox when you launch the sample.
 
chaiwarat@gmail.com
Topic Author
Posts: 3
Joined: 08 Jun 2017, 03:24

Re: need d3d11 sample with MVVM and code behind

14 Jun 2017, 04:30

Dear support,

That's clear for the view model.

The remaining question is the code behind.
For example, if I have TextBox.xaml.cs and I have a constructor doing some initialization.
Will it work automatically when load with the command below?

var content = (Noesis.Grid)Noesis.GUI.LoadXaml("TextBox.xaml");

The d3d11 sample project does not include TextBox.xaml in the csproj. The xaml file is just an external file.
If I have a .xaml.cs file, I need to include both .xaml and .xaml.cs into the project to compile.
So, should I use this LoadXaml command or other method to handle this environment.

Thank you.
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: need d3d11 sample with MVVM and code behind

14 Jun 2017, 16:00

The code behind class must specify the associated xaml that will be loaded when root class is instantiated.
For example, if I have the following xaml:
<UserControl x:Class="Samples.TextBoxSample"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  ...
</UserControl>
The code behind will look like this:
namespace Samples
{
  public class TextBoxSample : Noesis.UserControl
  {
    public TextBoxSample()
    {
      InitializeComponent();
    }

    private void InitializeComponent()
    {
      Noesis.GUI.LoadComponent("TextBox.xaml");
    }
    
    ...
  }
}
This user control can now be loaded directly calling Noesis.GUI.LoadXaml("TextBox.xaml"), or included in another xaml by referencing the root class:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:Samples">
    <local:TextBoxSample .../>
</Grid>
Either way an instance of the TextBoxSample code-behind class will be created.

Who is online

Users browsing this forum: Google [Bot] and 1 guest