Any Double Click Event of nodes and text labels in Syncfusion Diagram? - winforms

I'm developing a workflow system in which I have to open different types of forms on double click of text labels or bitmap nodes.
Can you please suggest relevant controls with such functionality or guide me if Syncfusion provides such functionality in diagram control ?
If they provide how can I use that?

Syncfusion provides the support to achieve your requirement. We suggest you to use diagram.EventSink’s “NodeDoubleClick” Event to hook the Node Double Click event.
Please refer the below code for better understanding.
[C#]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//To Disable the Label editor of the Nodes
diagram1.Controller.InPlaceEditing = false;
TextNode txt = new TextNode("Syncfusion", new RectangleF(100, 100, 100, 70));
diagram1.Model.AppendChild(txt);
BitmapNode bitmp = new BitmapNode("../../sync.JPG");
diagram1.Model.AppendChild(bitmp);
//To hook the Node Double click event
diagram1.EventSink.NodeDoubleClick += EventSink_NodeDoubleClick;
}
void EventSink_NodeDoubleClick(NodeMouseEventArgs evtArgs)
{
if(evtArgs.Node is BitmapNode || evtArgs.Node is TextNode)
{
//Write Logics to open new forms
}
}

Related

Use wait icon when a window is loaded in wpf

I am writing a wpf application which pulls data from excel sheet on clicking a button and loads another window where a datagrid is present which displays the result.
Now it takes 10-12 seconds to load the second window and during this time my application freezes. Now what I want is to display a little circular ribbon shaped button which will revolve and a "Please wait" text is displayed. This will be displayed in the centre of the first window and the other contents of the first window will become dimmer.
After the second windows is loaded , the first window closes.
Please tell me how to do this.
The problem is resolved. Thanks a lot for your help. Following is the code I used.
namespace ScoreX
{
public partial class Score : Window
{
Applications ap;
public Score()
{
InitializeComponent();
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
//cb is Circular progress bar
cbProgress.Visibility = Visibility.Hidden;
//Some codes
}
private void btnProceed_Click(object sender, RoutedEventArgs e)
{
//Some lines of Codes
Thread t1 = new Thread(new ThreadStart(CalculateData));
t1.SetApartmentState(ApartmentState.STA);
t1.Start();
cbProgress.Visibility = Visibility.Visible;
}
private void CalculateData()
{
//Some codes
Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
{
ap = new Applications();
this.Close();
ap.ShowDialog();
}
);
}

drag and drop in wpf user control

I had created a drag and drop control in wpf to drag and drop data between two list boxes which worked as a charm until I moved it to another project.
The difference being It was initially a wpf window and used the window object to get the mouse position and the position of the controls inside.
this.topWindow = Window.GetWindow(this.sourceItemsControl); //Source items control is instance of ItemsControl
bool previousAllowDrop = this.topWindow.AllowDrop;
this.topWindow.AllowDrop = true;
and now I had to change it to a user control instead, since its a part of a bigger project which is a Windows forms project and the views are linked as a Smart Part from the main project. So now the Window object is null.
I looked for a similar functionality for User Control but could not find it..What is it that I am missing out?? I know there should be something..Would appreciate any help on the same..
P.S. : I am using the MVVM architecture
Found the way to find the base User control using recursion, Thanks to ekholm for the heads up..
public static UserControl FindParentControl(DependencyObject child)
{
DependencyObject parent = VisualTreeHelper.GetParent(child);
//CHeck if this is the end of the tree
if (parent == null) return null;
UserControl parentControl = parent as UserControl;
if (parentControl != null)
{
return parentControl;
}
else
{
//use recursion until it reaches a Window
return FindParentControl(parent);
}
}
Now this base user control can be used to find the coordinates (reference) as well as setting other properties like AllowDrop, DragEnter, DragOver etc.
If you need MVVM, than you may examine this solution:
in your .xaml file add:
<ContentControl Content="{Binding Content, Mode=TwoWay}" AllowDrop="True" Name="myDesignerContentControl" />
Than in your ViewModel add the following:
private Panel _content;
public Panel Content {
get { return _content; }
set {
_content = value;
if (_content != null) {
RegisterDragAndDrop();
}
base.RaisePropertyChanged("Content");
}
}
private void RegisterDragAndDrop() {
Content.Drop += OnDrop;
Content.PreviewMouseLeftButtonDown += OnMouseLeftButtonDown;
Content.PreviewDragOver += OnDragOver;
}
private void OnDesignerDrop(object sender, DragEventArgs e) {
//some custom logic handling
}
private void OnDesignerMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
var control = (FrameworkElement)e.Source;
//some custom logic handling for doing drag & drop
}
private void OnDesignerDragOver(object sender, DragEventArgs e) {
//some custom logic handling for doing drag over
}
The idea is that you should use controls instead of mouse positions, it will be more simple and logical approach. The code above is an example of approach to use in MVVM for having an content area on which you may perform drag and drop of some controls. The idea behind is also suitable for drag and drop data between two list boxes, that you may have on the same content area.
Hope this helps.

undo/redo command stack for InkCanvas

I am creating paint like application using InkCanvas , I am willing to implement Undo
and Redo functionality in my application .
Which is the best way to implement Undo / Redo for InkCanvas ??
I've implemented undo / redo for a WPF application and ended up publishing my undo / redo code to http://muf.codeplex.com/. You can also get it via NuGet. Just look for "MUF" or "Monitored Undo Framework". It includes support for Silverlight 4.0, as well as .NET 3.5, 4.0, and WP7.
In my WPF app, we also had an InkCanvas that supported Undo / Redo. In my case, the strokes for the InkCanvas were saved to a database with the rest of the data. I hooked the various events on InkCanvas to detect when the strokes had changed. Then used these events to update the entities.
The entities tracked the changes to the strokes and integrated into the Undo / Redo library. When the user clicked Undo, the library would alter the entities back to their original state. Then I'd push those strokes back into the InkCanvas and trigger a layout update.
Comments and questions are welcome on the codeplex site ( http://muf.codeplex.com/ ). You'll also find complete documentation and sample apps there.
I know its too late but if someone is here for InkCanvas only than this answer might help:
public partial class MainWindow : Window
{
System.Windows.Ink.StrokeCollection _added;
System.Windows.Ink.StrokeCollection _removed;
private bool handle = true;
public MainWindow()
{
InitializeComponent();
inkCanvas1.Strokes.StrokesChanged += Strokes_StrokesChanged;
}
private void Strokes_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
{
if(handle)
{
_added = e.Added;
_removed = e.Removed;
}
}
private void Undo(object sender, RoutedEventArgs e)
{
handle = false;
inkCanvas1.Strokes.Remove(_added);
inkCanvas1.Strokes.Add(_removed);
handle = true;
}
private void Redo(object sender, RoutedEventArgs e)
{
handle = false;
inkCanvas1.Strokes.Add(_added);
inkCanvas1.Strokes.Remove(_removed);
handle = true;
}
}
And in XAML:
<InkCanvas x:Name="inkCanvas1" Width="100" Height="100" Background="Yellow"/>
<Button Content="Undo" Click="Undo" />
<Button Content="Redo" Click="Redo"/>
I don't know if this helps.. But one very easy way to UNDO is:
YourWindow.xaml.cs
private void Undo_Click(object sender, RoutedEventArgs e)
{
if (YourInkCanva.Strokes.Count > 0)
{
YourInkCanva.Strokes.RemoveAt(YourInkCanva.Strokes.Count - 1);
}
else
{
// Else Do Nothing.
}
}
You would want to replace YourInkCanva with the name of your inkcanva.

Winforms, Combobox, Databinding... allow user to type in a value not found in the DataSource

Just like the title says... I have a Winforms application with a databound dropdown. I want the user to have the convenience to pick from a bunch of predefined values, but also the ability to type in his own value
If I just enable databinding and set dropdown type to anything but DropDownList, it allows me to enter anything I want, but does not persist it to the objects...
Seems like a simple problem to solve... help?
I've added an event handler on ComboBox.Leave this code would add the newly typed in string in the combobox to the underlying list(countries) as well as refresh the combobox binding to it.
Limitations
You'd have to handle the addition of new element based on the type of datasource you have.
The List.Contains is case sensitive you might want to keep all the strings in one case. And convert the user entered value to that case before deciding to add it to the datasource.
Here you go, modify the comboBox1_Leave eventhandler according to your datatypes and datasource.
public partial class Form1 : Form
{
private List<string> countries;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
countries = new List<string>();
countries.Add("Australia");
countries.Add("Belgium");
countries.Add("Canada");
comboBox1.DataSource = countries;
}
private void comboBox1_Leave(object sender, EventArgs e)
{
ComboBox combo = (sender as ComboBox);
CurrencyManager cm = (combo.BindingContext[combo.DataSource] as CurrencyManager);
if (!cm.List.Contains(combo.Text))
{
cm.List.Add(combo.Text);
cm.EndCurrentEdit();
cm.Refresh();
cm.Position = cm.Count - 1;
}
}
}

Multiple Command Binding

Is it possible to bind the multiple commands to the button.
I have a user control, which i am calling in my main application (parent application).
I want to handle a click command on both the controls (the user control as well as on the main window). However i am only able to get one.
Is there any way in which i can get this.
Any help is really appreciated.
Code Snippet:
public class MainWindowFooterCommands
{
public static readonly RoutedUICommand FooterClickLocalCommand = new RoutedUICommand("Local Button Command", "FooterClickLocalCommand", typeof(MainWindowFooterCommands));
}
private void MainWindowFooterBindCommands()
{
CommandBinding cmdBindingBXClick = new CommandBinding(MainWindowFooterCommands.FooterClickLocalCommand);
cmdBindingBXClick.Executed += ClickCommandHandler;
CommandBindings.Add(cmdBindingBXClick);
}
void ClickCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
//Do Something
}
//Parent Control holding an instance of the footer control.
class MainWindow {
public MainWindow()
{
CommandBinding cmdBindingBXClick1 = new CommandBinding(MainWindowFooterCommands.BXClickMainWindowCommand);
cmdBindingBXClick1.Executed += LoadParent;
CommandBindings.Add(cmdBindingBXClick1);
}
public void LoadParent(object sender, ExecutedRoutedEventArgs e)
{
LoadParentWindow();
}
}
Regards,
Tushar
You might be trying to aggregate multiple commands, which is a natural thing to want to do.
If you are using Prism, there is a class builtin for this called the CompositeCommand (scroll down a bit): https://msdn.microsoft.com/en-us/library/ff921126.aspx
Otherwise, Josh Smith has a very good article on his implementation called a "Command Group": http://www.codeproject.com/KB/WPF/commandgroup.aspx
There are some very nice scenarios you can rollup like this (for instance, "Save All"). A good tool for your bag of tricks.
AFAIK WPF doesnt offer anything out of the box to support multiple commandbindings at various levels, but you could try the following:
void ClickCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
IInputElement parent = (IInputElement) LogicalTreeHelper.GetParent((DependencyObject)sender);
MainWindowFooterCommands.BXClickMainWindowCommand.Execute(e.Parameter, parent);
}
You might have to test whether your parent really is an IInputElement, though.

Resources