WPF Context menu on left click

Here is a XAML only solution. Just add this style to your button. This will cause the context menu to open on both left and right click. Enjoy! <Button Content=”Open Context Menu”> <Button.Style> <Style TargetType=”{x:Type Button}”> <Style.Triggers> <EventTrigger RoutedEvent=”Click”> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty=”ContextMenu.IsOpen”> <DiscreteBooleanKeyFrame KeyTime=”0:0:0″ Value=”True”/> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Style.Triggers> <Setter Property=”ContextMenu”> … Read more

Bind button in DataTemplate to command in the form’s ViewModel

It’s: {Binding DataContext.FireCommand, RelativeSource={RelativeSource AncestorType=ListBox}} No need to walk up to the root unless you actually change the DataContext along the way, but as the ListBox seems to bind to a property on the main VM this should be enough. The only thing i recommend reading is the Data Binding Overview, and the Binding class … Read more

How to use AlternationIndex in ItemsControls?

The ItemContainerStyle is applied to the elements generated by the ItemsControl: ContentPresenter. The ContentPresenter will in turn contain whatever you put in your ItemTemplate. In the case of a ListBox, the ItemContainerStyle is applied to the generated ListBoxItem. The AlternationCount is, based on what you posted, only available on these generated items. You cannot use … Read more

MVVM for winforms [duplicate]

I think that there are two answers here… really just one answer to “Should I” and one answer to “Could I”. As far as “Could I”, it is certainly possible. MVVM really just relies on a view that can bind to a view model. Since WinForms supports binding, this certainly is possible. You may need … Read more

WPF MVVM INotifyPropertyChanged Implementation – Model or ViewModel

The thing is that if you were following MVVM, you would have a BookViewModel for your Book model class. So you would have a INotifyPropertyChanged implementation on that view model. Exactly for that purpose MVVM exists (but not only). That being said, the INotifyPropertyChanged has to be implemented on view model classes, not models. UPDATE: … Read more

Knockout.js Make every nested object an Observable

I would use the knockout mapping plugin. var jsonData = { id : 1, details: { name: “Johnny”, surname: “Boy” } } var yourMapping = { ‘details’: { create: function(options) { return Details(options.data); } } } function Details(data) { ko.mapping.fromJS(data, {}, this); } function YourObjectName() { ko.mapping.fromJS(jsonData, yourMapping, this); } This will create your object … Read more

How to inject a ViewModel into a composable function using Hilt (Jetpack Compose)

From version androidx.hilt:hilt-navigation-compose:1.0.0-alpha02 you can inject view model into Composable functions by: hiltViewModel<ViewModelType>() Example: @Composable fun LoginScreen(viewModel: LoginViewModel) {} LoginScreen( viewModel = hiltViewModel<LoginViewModel>() ) Android Developer Documentation compose and hilt UPDATE: import androidx.hilt.navigation.compose.hiltViewModel @Composable fun LoginScreen( viewModel: LoginViewModel = hiltViewModel() ){ val videos=vm.watchLater.observeAsState() val context= LocalContext.current }

What is the difference between MVI compared to MVC and MVVM

from my experience each architecture pattern of those was invented to solve specific problem that the previous one ignored or wasn’t observed yet. MVC – Model View Controller in UI applications the responsibilty of rendering the data to the screen, or the business logic and bind those together at first wasn’t clear. so MVC came … Read more

ReSharper WPF error: “Cannot resolve symbol “MyVariable” due to unknown DataContext”

This error is produced by ReSharper when designing XAML for WPF, and indicates that the XAML cannot find the class that contains run-time bindings. This usually indicates that the DataContext is not set properly. This error means that: Intellisense for XAML does not work as well at design time; One cannot auto navigate from the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)