by robotix1986
25. October 2009 21:41
Hi Folks,
This time, back to WPF. I thought of using the drag & drop functionality in WPF. Just some experiments. Half-way through my coding. A DCR you may say.
I went through the
WPF documentation on MSDN, which seemed pretty straight-forward. I added the AllowDrop="True" tag to a ListView control for which I needed this feature. And I Compiled it.
So far so good. Then I tried dropping a file onto the ListView. However, no luck. All I got is the forbidden icon.
Hmm. Maybe it's some logic in my code that's preventing this from happening. I created a sample app with just the single ListBox. Still the same result.
I searched a couple of blogs. All examples were either similar or exactly the same as mine.
http://www.kirupa.com/blend_wpf/drag_drop_files_wpf_pg1.htm
http://www.codeproject.com/KB/WPF/WPF_Drag_And_Drop_Sample.aspx
http://msdn.microsoft.com/en-us/library/bb295243.aspx
Solution
Next, I started searching for issues with WPF drag & drop. No luck here either. Finally, found that Vista has an issue... or a "By Design" thing... which says that "Vista prevents lower security applications from giving data (and potentially hurting) higher level applications". It seems that same is the case with Windows 7.
Bingo... I was running VS and debugging as an Administrator. Running the application outside of VS makes it work perfectly fine. And thus I found my solution and my app it's drag & drop feature.
Till my next post
Regards,
AlD
by robotix1986
19. July 2009 11:44
So just some time back I got thinking... everytime I start reading mails in the C# discussion alias at my company or Eric Lippert's explanations in them... the first thing I do is open up my very extensively used Console Application project in Visual Studio, comment out the existing main function for future reference and start writing a new one... and it is kind of a pain to do this.. so I thought that it's time to get it automated.. so I wrote a snippet to do that for me.
Below is the code for that: -
|
<?
xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>mainfn</Title> <Shortcut>mainfn</Shortcut> <Description>Code snippet for 'Main' function</Description> <Author>Alvaro Rahul Dias</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> <SnippetType>SurroundsWith</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>expression</ID> <ToolTip>Code in main method</ToolTip> <Default>Console.WriteLine("Hello World!");</Default> </Literal> </Declarations> <Code Language="csharp"><![CDATA[ public class MyClass { public static void Main() { $expression$ $selected$ $end$ } }]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets> |
Most of the fields above are self explanatory. I'll explain a few important ones.
The <Shortcut> tag specifies what you need to type in VS to use this snippet.
<SnippetTypes> - where you can use this snippet, Expansion, Surround With or both.
<Code Language="csharp"> - the actual code to be inserted
Interesting thing to note is that all the variable items are marked with $ signs. The $selected$ attribute signifies where the selected code should go in case you use this code as a sorround with snippet.
The $end$ attribute signifies where the cursor should go once you're finished with the snippet.
Hope the above helps in your coding adventures.
Regards,
AlD
by robotix1986
16. July 2009 16:02
Well this entry is all code.. no explanations... you figure it out yourselves
Microsoft.SqlServer.Dts.Runtime.
Package package = new Microsoft.SqlServer.Dts.Runtime.Package();
Executable executable = package.Executables.Add("STOCK:PipelineTask");
Microsoft.SqlServer.Dts.Runtime.TaskHost thMainPipe = executable as Microsoft.SqlServer.Dts.Runtime.TaskHost;
MainPipe dataFlowTask = thMainPipe.InnerObject as MainPipe;
// Add a flat file destination component to the data flow task
IDTSComponentMetaData100 destinationComponent = dataFlowTask.ComponentMetaDataCollection.New();
destinationComponent.Name = "FlatFileDestination";
destinationComponent.ComponentClassID = "DTSAdapter.FlatFileDestination";
// Get the design time instance of the flat file destination component.
CManagedComponentWrapper destinationInstance = destinationComponent.Instantiate();
// Initialize the flat file destination component
destinationInstance.ProvideComponentProperties();
// Configure the flat file destination component to use the Flat File connection manager
destinationComponent.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(destinationConnection);
destinationComponent.RuntimeConnectionCollection[0].ConnectionManagerID = destinationConnection.ID;
// Configure the custom properties of the Flat File destination component
destinationInstance.SetComponentProperty("Header", "");
destinationInstance.SetComponentProperty("Overwrite", true);
// Reinitialize the metadata.
destinationInstance.AcquireConnections(null);
destinationInstance.ReinitializeMetaData();
destinationInstance.ReleaseConnections();
// ADD OTHER TASKS HERE
Hope this helps.
Regards,
AlD