Donnerstag, 22. August 2013

wpf mvvm? drag and drop? easy? fast result?

This is not a 100% wpf mvvm approach, because this solution will use the help of the default code behind file. As we know, we should avoid touching the code behind file in case of a clean mvvm. Calling a ViewModel-method through the drop event of the default code behind file....

in the code behind file:

using MyProject.MyViewModels;

...
private void UserControl_Drop(object sender, DragEventArgs e)
{
      (this.DataContext as UserControlVieModel).OnDrop(sender, e);
}


in the ViewModel:

public void OnDrop(object sender, System.Windows.DragEventArgs e)
{
            ExampleText= "dropped";
} 

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

how to update the UI from another thread / parallel task

Use MYCLASS.Dispatcher.Invoke and post code for the queue of the UI thread.
Imagine, you will fill a listbox in an async & await initialized parallel thread or in another object.

...
MyMainWindowInstance.Dispatcher.Invoke(DispatcherPriority.Normal, (Actiondelegate() { MyMainWindowInstance.MyListBox.Items.Add("from parallel!!!!!!!!"); }  );
...

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Dienstag, 13. August 2013

How to bind to a static resource of - for instance - App.xaml.cs class?

1) define the appropriate Namespace of your Project in XAML...

                        xmlns:Project="clr-namespace:MyCurrentProject"


2) bind a property (IsEnabled)  to a boolean static source in XAML (for instance isRegistered true/false) ...

           ...             IsEnabled="{Binding Source={x:Static Project:App.isRegistered}}"  ...

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

How to show a tooltip only if the element/target is disabled/is not enabled ...

<button click="myButton_Click_1" content="Testtext" isEnabled="{Binding myButtonIsEnabledState}" name="myButton"
ToolTip="{Binding disabledStateToolTipText}" ToolTipService.isEnabled="{Binding Source={x:Static ProjectNamespace:App.isNotRegistered}}" ToolTipService.showOnDisabled="True"> </button>
The Default behavior is to Switch off the ToolTip via ToolTipService.isEnabled +++ The ToolTip will only be active, if the Button is not enabled using ToolTipService.IsEnabled property, because ToolTipService.showOnDisabled="True" overrides the previous "false"-ToolTip functionality.

myButtonIsEnabledState = true or false ViewModel Member for basic button on/off  

disabledStateToolTipText = text to show as a tooltip

App.isNotRegistered = here global static true/false-Switch to modify the tooltip visibility

Benefit from the best Windows Desktop app in the world and use Strokey.Net!