mirror of
https://github.com/ckaczor/Common.Wpf.git
synced 2026-01-14 01:25:37 -05:00
Initial commit
This commit is contained in:
29
TextListControl/TextList.xaml
Normal file
29
TextListControl/TextList.xaml
Normal file
@@ -0,0 +1,29 @@
|
||||
<ListBox x:Class="Common.Wpf.TextListControl.TextList"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="300"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}"
|
||||
TextWrapping="Wrap"
|
||||
Margin="0,1" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type ListBoxItem}">
|
||||
<EventSetter Event="MouseEnter"
|
||||
Handler="handleListItemMouseEnter" />
|
||||
<EventSetter Event="MouseLeave"
|
||||
Handler="handleListItemMouseLeave" />
|
||||
<EventSetter Event="MouseUp"
|
||||
Handler="handleListItemMouseUp" />
|
||||
<EventSetter Event="MouseDoubleClick"
|
||||
Handler="handleListItemMouseDoubleClick" />
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
95
TextListControl/TextList.xaml.cs
Normal file
95
TextListControl/TextList.xaml.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Common.Wpf.TextListControl
|
||||
{
|
||||
public partial class TextList : ListBox
|
||||
{
|
||||
#region Events
|
||||
|
||||
public static RoutedEvent ListItemMouseUpEvent = EventManager.RegisterRoutedEvent("ListItemMouseUp", RoutingStrategy.Bubble, typeof(MouseButtonEventArgs), typeof(TextList));
|
||||
public event MouseButtonEventHandler ListItemMouseUp;
|
||||
|
||||
public void OnListItemMouseUp(object listBoxItem, MouseButtonEventArgs e)
|
||||
{
|
||||
MouseButtonEventHandler handler = ListItemMouseUp;
|
||||
if (handler != null) handler(listBoxItem, e);
|
||||
}
|
||||
|
||||
public static RoutedEvent ListItemMouseDoubleClickEvent = EventManager.RegisterRoutedEvent("ListItemMouseDoubleClick", RoutingStrategy.Bubble, typeof(MouseButtonEventArgs), typeof(TextList));
|
||||
public event MouseButtonEventHandler ListItemMouseDoubleClick;
|
||||
|
||||
public void OnListItemMouseDoubleClick(object listBoxItem, MouseButtonEventArgs e)
|
||||
{
|
||||
MouseButtonEventHandler handler = ListItemMouseDoubleClick;
|
||||
if (handler != null) handler(listBoxItem, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public TextList()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hover selection events
|
||||
|
||||
private void handleListItemMouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
// Make sure the control has focus
|
||||
Focus();
|
||||
|
||||
// Get the list box item
|
||||
ListBoxItem listBoxItem = (ListBoxItem) sender;
|
||||
|
||||
// Select the data context
|
||||
SelectedItem = listBoxItem.DataContext;
|
||||
|
||||
// Set the cursor
|
||||
listBoxItem.Cursor = Cursors.Hand;
|
||||
}
|
||||
|
||||
private void handleListItemMouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
// Clear selection
|
||||
SelectedItem = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region List item events
|
||||
|
||||
private void handleListItemMouseUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
|
||||
{
|
||||
// Get the list box item
|
||||
ListBoxItem listBoxItem = (ListBoxItem) sender;
|
||||
|
||||
// Build the event args
|
||||
MouseButtonEventArgs eventArgs = new MouseButtonEventArgs(mouseButtonEventArgs.MouseDevice, mouseButtonEventArgs.Timestamp, mouseButtonEventArgs.ChangedButton);
|
||||
eventArgs.RoutedEvent = ListItemMouseUpEvent;
|
||||
|
||||
// Raise the event
|
||||
OnListItemMouseUp(listBoxItem, eventArgs);
|
||||
}
|
||||
|
||||
private void handleListItemMouseDoubleClick(object sender, MouseButtonEventArgs mouseButtonEventArgs)
|
||||
{
|
||||
// Get the list box item
|
||||
ListBoxItem listBoxItem = (ListBoxItem) sender;
|
||||
|
||||
// Build the event args
|
||||
MouseButtonEventArgs eventArgs = new MouseButtonEventArgs(mouseButtonEventArgs.MouseDevice, mouseButtonEventArgs.Timestamp, mouseButtonEventArgs.ChangedButton);
|
||||
eventArgs.RoutedEvent = ListItemMouseDoubleClickEvent;
|
||||
|
||||
// Raise the event
|
||||
OnListItemMouseDoubleClick(listBoxItem, eventArgs);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user