converter

Default ValueConverter for a class in WPF

自作多情 提交于 2019-12-06 15:39:53
I'm just about to start a new project of mine and am currently evaluating some techniques for localization, modularity etc. I have (at least in my opinion) a pretty good approach to localization but now I struggle to find a good solution for databinding. I want to bind values of textfields etc. (UIElements in general) to a specific method in the DataContext of the form. The method looks like this: public void GetValue(string name) where name is a "path" in the form of "node/subnode/subsubnode". I thought about using a ValueConverter for the binding and this worked out pretty good till now. My

Converting very large files from xml to csv

我们两清 提交于 2019-12-06 15:18:20
Currently I'm using the following code snippet to convert a .txt file with XML data to .CSV format. My question is this, currently this works perfectly with files that are around 100-200 mbs and the conversion time is very low (1-2 minutes max), However I now need this to work for much bigger files (1-2 GB's each file). Currently the program freezes the computer and the conversion takes about 30-40 minutes with this function. Not sure how I would proceed changing this function. Any help will be appreciated! string all_lines = File.ReadAllText(p); all_lines = "<Root>" + all_lines + "</Root>";

Replace string value with '0' when string is empty

若如初见. 提交于 2019-12-06 15:11:58
问题 I'm taking a value from a textbox and converting it to decimal. But, the textbox value could be empty. So, how could I handle empty strings from the textbox? Unfortunately I have around 50 textboxes to deal with, so answers like 'check for null with IF condition' won't help me. My code will look ugly if I use all those IF conditions. I have this Convert.ToDecimal(txtSample.Text) To handle nulls, I did this Convert.ToDecimal(txtSample.Text = string.IsNullOrEmpty(txtSample.Text) ? "0" :

Converting .rtf files to .doc and then .doc back to .rtf in PowerShell (WMF registry fix) - file size optimization

房东的猫 提交于 2019-12-06 13:55:26
问题 I need to create a script in powershell with which will convert all my files from .rtf to .doc and then back. I want to do it because I have applied registry fix which will decrease size of my rtf files after such conversion ( It will not save second WMF image specyfic info http://support.microsoft.com/kb/224663 ).I imagine my script workflow as RTF_1 save to doc then close rtf1 delete rtf 1 , save doc to rtf2 , close doc , delete doc. 回答1: Here is the final working script ( without deleting

How can I dynamically change the converter on DataGridTextColumn binding in WPF?

六眼飞鱼酱① 提交于 2019-12-06 13:38:51
I really don't understand WPF and XAML, and inherited some terribly written code, so I may be butchering this, but here goes. I inherited a DataGrid bound (in code behind) to a list of Person objects, where the necessary DataGridTextColumns are specified in XAML (presumably to allow styling). <DataGrid x:Name="PersonGrid" ItemsSource="{Binding}" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding Path=LastName}" MaxWidth="Infinity" MinWidth="150" Header="Last Name"> <DataGridTextColumn Binding="{Binding Path=FirstName}" MaxWidth="Infinity" MinWidth="150"

JSON convert Map with Integer keys

懵懂的女人 提交于 2019-12-06 13:11:47
I have a small sample of test code where I try to convert a Map into a JSON string and back. While parsing from the JSON string, the resulting map contains the String key "1" instead of the Integer key "1", thus making the test fail. The same happens with POJOs used as the key to this map. Is this behaviour expected or have I ommited some configuration for the JSON converters? public class SampleConverterTest { @Test public void testIntegerKey() { // Register an Integer converter JSON.registerConvertor(Integer.class, new JSONPojoConvertor(Integer.class)); Map<Integer, String> map = new HashMap

How can a bot receive a voice file from Facebook Messenger (MP4) and convert it to a format that is recognized by speech engines like Bing or Google?

拈花ヽ惹草 提交于 2019-12-06 12:48:36
I'm trying to make a bot for Facebook Messenger using Microsoft's Bot Framework that will do this: Get a user's voice message sent via Facebook Messenger Convert speech to text Do something with it There's no problem with getting the voice message from Messenger (the URL can be extracted from the message the bot receives), and there's also no problem with converting an audio file to speech (using Bing Speech API or Google's similar API). However, these APIs require PCM (WAV) files, while Facebook Messenger gives you an MP4 file. Is there a popular/standard way of converting one format into

Java Currency Converter GUI

自作多情 提交于 2019-12-06 12:48:10
问题 I'm trying to make a simple java currency converter GUI. So far I have this :(4 parts) How would I set the values for each item in the jcombbox (ex. each currency) so that I can use them to calculate the conversion? Here's the first part (1 combobox): import java.awt.*; import java.awt.event.*; import javax.swing.*; public class test extends JPanel { private JPanel panel; private JLabel messageLabel; private JTextField USDTextField; private JPanel CurrencyPanel; private JComboBox CurrencyBox;

OpenCV for Android: Convert Camera preview from YUV to RGB with Imgproc.cvtColor

我是研究僧i 提交于 2019-12-06 11:27:57
问题 I get a runtime error if I try to convert camera preview YUV byte array to a RGB(A) byte array with Imgproc.cvtColor( mYUV_Mat, mRgba_Mat, Imgproc.COLOR_YUV420sp2RGBA, 4 ) in onPreviewFrame(byte[] data, Camera camera): Preview.java: mCamera.setPreviewCallback(new PreviewCallback() { public void onPreviewFrame(byte[] data, Camera camera) { // Pass YUV data to draw-on-top companion System.arraycopy(data, 0, mDrawOnTop.mYUVData, 0, data.length); mDrawOnTop.invalidate(); } }); DrawOnTop.java:

C# How are arrays stored in memory

痞子三分冷 提交于 2019-12-06 07:49:08
I guess my main question is, will this always work as long as I don't re-initialize (new byte[#]) the array that was passed as the parameter? static unsafe decimal GetDecimal(byte[] ba) { decimal* decimal_PTR; fixed (byte* byte_PTR = &ba[0]) { decimal_PTR = ((decimal*)byte_PTR); } return *decimal_PTR; } I'm not sure how C# handles arrays in memory. I didn't even know they were managed types until about an hour ago. I just want to know if I pass in a decimal as a byte[], will it always return the correct value? Any other information you can provide is appreciated. After @MJLaukala's