Note that there are some explanatory texts on larger screens.

plurals
  1. POFailing to store File In Combobox and Read the Data, Size in WPF
    primarykey
    data
    text
    <p>I am a C++ developer and recently started working on C# WPF app. I am following MVVM. Well I am working on Combobox and buttons. Basically I have a browse button to load a binfile and store it in combobox and when I click TEST button, i should read the data present in file, get the size of it.</p> <p><strong>Here is the XAML:</strong></p> <pre><code>&lt;ComboBox Name="ClockYHZBox" &gt; &lt;ComboBoxItem Content="{Binding FirmwarePath}" /&gt; &lt;/ComboBox&gt; &lt;Button Content="Browse" Command="{Binding WriteFilePathCommand}" Name="RunPCMPDM0" /&gt; &lt;Button Content="Test" Command="{Binding WriteDataTestCommand}" /&gt; </code></pre> <p><strong>ViewModel Class:</strong></p> <pre><code>private string _selectedFirmware; public string FirmwarePath { get; set; } // This method gets called when BROWSE Button is pressed private void ExecuteWriteFileDialog() { var dialog = new OpenFileDialog { InitialDirectory = _defaultPath }; dialog.DefaultExt = ".bin"; dialog.Filter = "BIN Files (*.bin)|*.bin"; dialog.ShowDialog(); FirmwarePath = dialog.FileName; // Firmware path has the path } // Method gets called when TEST Button is Pressed public void mSleepTestCommandExecuted() { int cmd = (22 &lt;&lt; 8) | 0x06; System.IO.StreamReader sr = new System.IO.StreamReader(FirmwarePath); string textdata = sr.ReadToEnd(); int fileSize = (int)new System.IO.FileInfo(FirmwarePath).Length; Byte[] buffer = new Byte[256]; // This gives me the size and data, But i am failing to do // further operation of storing value in BUFFER // and MEMCPY which is shown below in C++ Code } </code></pre> <p>This is how I had done in my C++ application:</p> <pre><code>MemoryBlock binFile; m_wdbFile-&gt;getCurrentFile().loadFileAsData(binFile); //m_wbdFile is a filedialog object BYTE *buffer = NULL; int fileSize = binFile.getSize(); buffer = (BYTE *)calloc(sizeof(BYTE), fileSize + 2); memcpy(buffer+2, binFile.getData(), fileSize); </code></pre> <p>As you can see above, it opens the file, stores the size in <code>fileSize</code>, allocates block of memory to buffer and so on. How can I achieve it? I would appreciate your help :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload