Posts

Showing posts from May, 2017

Detecting 'MouseOver' events in WPF / MVVM

Image
Useful StackOverflow link https://stackoverflow.com/questions/36221118/how-to-make-mouseover-event-in-mvvm Step 1: Create a new WPF project Step 2: Create an example WPF window MainWindow.xaml [code language="xml"] <Window x:Class="MouseOverEventMvvm.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:MouseOverEventMvvm" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <local:MainWindowViewModel /> </Window.Da...

How to get mouse cursor position in WPF MVVM applications using Dependency Properties

Image
Very useful StackOverflow link , Mark Green 's answer, from which I have borrowed heavily here, with one or two modifications in order to fully work in a Visual Studio 2015 environment. Step 1: Create a new WPF project Step 2: Create an example WPF window MainWindow.xaml [code language="xml"] <Window x:Class="MousePositionMvvm.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:MousePositionMvvm" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" mc:Ignorable="d" Title="MainWindow" Height="450" Width="525"> <Window....

Setting the visibility of individual GridViewColumn items in WPF

Image
Some instructions for setting the visibility of GridViewColumn items in WPF. Some useful StackOverflow links as follows: https://stackoverflow.com/questions/1392811/c-wpf-make-a-gridviewcolumn-visible-false Helge Klein 's contribution was particularly useful. Step 1: Create a new WPF application Step 2: Create the ViewModel class Our ViewModel class for inserting items into our ListView plus other required properties... Inherits from INotifyPropertyChanged in order to implement the OnPropertyChanged. MainWindowViewModel.cs [code language="csharp"] using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using EnableWpfColumn.Annotations; namespace EnableWpfColumn { public class Item { public Item(string name, string matches) { Name = name; Matches = matches; } public string Name { get; set; } public string Matches { get; set; } } public clas...

Displaying changing graphics in Java

Some hints on how to display changing graphics in Java using a simple example I have borrowed from the following site: http://www.dreamincode.net/forums/topic/30222-working-with-graphics-in-java/ I use the same approach to draw a number of concentric circles of differing sizes, but with a small delay in between each draw, refreshing the display at each iteration to give the illustration of the changing graphics. Full Java code follows: [code language="java"] import java.awt.*; import javax.swing.*; public class MainApp extends JPanel { private static final long serialVersionUID = 1L; static JFrame frame = new JFrame("BullsEye"); static int endpoint = 220; static int x, y; public static void main(String args[]) { MainApp eye = new MainApp(); frame.add(eye); frame.setSize(300,300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for (x = 20; x <= 110; x += 10) ...

Using HierarchicalDataTemplate with TreeView in WPF / MVVM

Image
Some instructions on how to create and display a hierarchical data structure in WPF by using HierarchicalDataTemplate with TreeView Visual Studio 2019 project downloadable from here. Stack Overflow link Step 1: Create a new WPF application Step 2: Create the model class The Model class we use to define our Directory 'Item' structure. In this instance I'm keeping things really simple, just a 'Name' and a List of other 'DirectoryItem' objects. Also contained in this class is a recursive function to traverse the 'DirectoryItem' node elements: Model.cs [code language="csharp"] using System.Collections.Generic; namespace WpfTreeViewBinding.Model { public class Item { public string Name { get; set; } } public class DirectoryItem : Item { public DirectoryItem() { Items = new List<DirectoryItem>(); } public List<DirectoryItem> Items { get; set; } ...