Chapter.Net.WPF.Behaviors
2.1.0
dotnet add package Chapter.Net.WPF.Behaviors --version 2.1.0
NuGet\Install-Package Chapter.Net.WPF.Behaviors -Version 2.1.0
<PackageReference Include="Chapter.Net.WPF.Behaviors" Version="2.1.0" />
paket add Chapter.Net.WPF.Behaviors --version 2.1.0
#r "nuget: Chapter.Net.WPF.Behaviors, 2.1.0"
// Install Chapter.Net.WPF.Behaviors as a Cake Addin #addin nuget:?package=Chapter.Net.WPF.Behaviors&version=2.1.0 // Install Chapter.Net.WPF.Behaviors as a Cake Tool #tool nuget:?package=Chapter.Net.WPF.Behaviors&version=2.1.0
<img src="https://raw.githubusercontent.com/dwndland/Chapter.Net.WPF.Behaviors/master/Icon.png" alt="logo" width="64"/>
Chapter.Net.WPF.Behaviors Library
Overview
Brings additional behaviors to existing WPF controls.
Features
- ColumnSortBehavior: Enables sorting by click on the header on a ListView.
- ColumnVisibilityBehavior: Enables dynamically display and hide of columns of a ListView.
- ColumnWidthBehavior: Allows defining column sizes of a ListView.
- ComboBoxBehavior: Brings the definition of max text length of the combobox if it is editable.
- CutTooltipBehavior: Brings the functionality to the TextBlock and Label to show the text in the tooltip automatically when its cut.
- DoubleClickBehavior: Brings the feature to be able to double click any UI element.
- DragMoveBehavior: Enables that a window can be moved by the mouse when drop down on a content.
- DynamicResourceBehavior: Brings the possibility to create a dynamic resource out of a binding value.
- FocusBehavior: Brings the feature to set the focus to a specific element or on window launch.
- FrameworkBehavior: Brings commands for actions on FrameworkElements.
- KeyBlockBehavior: Disabled specific keys on a control.
- ListBehavior: Gives you some commands when clicking in an ItemsControl or its items.
- ScrollBehavior: Brings the feature to modify the scroll position of an items control.
- TextBoxBehavior: Brings the features to text boxes to define its selection or bound the selection part.
- WindowBehavior: Brings the feature to a Window to bind loading and closing action or easy close with dialog result.
- WindowTitleBarBehavior: Brings the feature to the Window to disable or hide elements in the title bar.
Getting Started
Installation:
- Install the Chapter.Net.WPF.Behaviors library via NuGet Package Manager:
dotnet add package Chapter.Net.WPF.Behaviors
ColumnSortBehavior:
- Usage
<DataTemplate x:Key="HeaderArrowUp"> <Grid> <TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center" /> <Path StrokeThickness="0" SnapsToDevicePixels="True" Data="M 0,4 L 4,0 L 8,4 L 0,4" Margin="0,-2,0,0" VerticalAlignment="Top" HorizontalAlignment="Center"> <Path.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="#FF3C5E72" Offset="0"/> <GradientStop Color="#FFC3E4F5" Offset="1"/> </LinearGradientBrush> </Path.Fill> </Path> </Grid> </DataTemplate> <DataTemplate x:Key="HeaderArrowDown"> <Grid> <TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center" /> <Path StrokeThickness="0" SnapsToDevicePixels="True" Data="M 0,0 L 4,4 L 8,0 L 0,0" Margin="0,-2,0,0" VerticalAlignment="Top" HorizontalAlignment="Center"> <Path.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="#FF3C5E72" Offset="0"/> <GradientStop Color="#FFC4E3F4" Offset="1"/> </LinearGradientBrush> </Path.Fill> </Path> </Grid> </DataTemplate> <DataTemplate x:Key="HeaderTransparent"> <Grid> <TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center" /> </Grid> </DataTemplate> <ListView controls:ColumnSortBehavior.AllowColumnSortings="True" controls:ColumnSortBehavior.AscendingSortHeaderTemplate="{StaticResource HeaderArrowUp}" controls:ColumnSortBehavior.DescendingSortHeaderTemplate="{StaticResource HeaderArrowDown}" controls:ColumnSortBehavior.NeutralHeaderTemplate="{StaticResource HeaderTransparent}"> <ListView.View> <GridView> <GridViewColumn Header="Name" controls:ColumnSortBehavior.IsDefaultSortColumn="True" controls:ColumnSortBehavior.SortPropertyName="Name" /> <GridViewColumn Header="Size" controls:ColumnSortBehavior.SortPropertyName="Size" /> <GridViewColumn Header="Date" controls:ColumnSortBehavior.SortPropertyName="Date" /> </GridView> </ListView.View> </ListView>
ColumnVisibilityBehavior:
- Usage
public class MainViewModel : ObservableObject { public MainViewModel() { VisibleColumnNames = new EnhancedObservableCollection<string> { "Name", "Size" }; } public EnhancedObservableCollection<string> VisibleColumnNames { get; private set; } }
<ListView controls:ColumnVisibilityBehavior.VisibleColumns="{Binding VisibleColumnNames}"> <ListView.View> <GridView> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" controls:ColumnVisibilityBehavior.Name="Name" /> <GridViewColumn Header="Size" DisplayMemberBinding="{Binding Size}" controls:ColumnVisibilityBehavior.Name="Size" /> <GridViewColumn Header="Date" DisplayMemberBinding="{Binding Date}" controls:ColumnVisibilityBehavior.Name="Date" /> </GridView> </ListView.View> </ListView>
ColumnWidthBehavior:
- Usage
<ListView controls:ColumnWidthBehavior.AutoSize="Proportional"> <ListView.View> <GridView> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" controls:ColumnWidthBehavior.ProportionalWidth="60" /> <GridViewColumn Header="Size" DisplayMemberBinding="{Binding Size}" controls:ColumnWidthBehavior.ProportionalWidth="30" /> <GridViewColumn Header="Date" DisplayMemberBinding="{Binding Date}" controls:ColumnWidthBehavior.ProportionalWidth="10" /> </GridView> </ListView.View> </ListView>
ComboBoxBehavior:
- Usage
<ComboBox IsEditable="True" controls:ComboBoxBehavior.MaxLength="30" />
CutTooltipBehavior:
- Usage
<TextBlock Text="{Binding AnyLongtext}" controls:CutTooltipBehavior.ShowTooltip="Width" />
DoubleClickBehavior:
- Usage
<TextBlock Text="Doubleclick Me" controls:DoubleClickBehavior.Command="{Binding ItemDoubleClicked}" controls:DoubleClickBehavior.CommandParameter="Parameter" />
DragMoveBehavior:
- Usage
<Window controls:DragMoveBehavior.Enabled="True"> </Window> <Window> <DockPanel> <Border Height="22" Background="Gray" controls:DragMoveBehavior.Enabled="True"> <TextBlock Text="{Binding Title}" /> </Border> <Grid> </Grid> </DockPanel> </Window>
DynamicResourceBehavior:
- Usage
<TextBlock controls:DynamicResourceBehavior.ResourceKey="{Binding MyTranslationKey}" />
FocusBehavior:
- Usage
<Window controls:FocusBehavior.ApplicationGotFocusCommand="{Binding SwitchedToApplicationCommand}" controls:FocusBehavior.ApplicationLostFocusCommand="{Binding SwitchedOutFromApplicationCommand}"> </Window> <Button controls:FocusBehavior.GotFocusCommand="{Binding ButtonGotFocusCommand}" controls:FocusBehavior.GotFocusCommandParameter="Example" /> <Button controls:FocusBehavior.LostFocusCommand="{Binding ButtonGotFocusCommand}" controls:FocusBehavior.LostFocusCommandParameter="Example" /> <Button controls:FocusBehavior.HasFocus="{Binding IsButtonFocused}" />
FrameworkBehavior:
- Usage
<Button controls:FrameworkBehavior.LoadedCommand="{Binding ButtonLoadedCommand" />
public class MainViewModel : ObservableObject { public MainViewModel() { ButtonLoadedCommand = new DelegateCommand(ButtonLoaded); } public DelegateCommand ButtonLoadedCommand { get; private set; } private void ButtonLoaded() { } }
KeyBlockBehavior:
- Usage
<Window controls:KeyBlockBehavior.BlockAll="True"> </Window>
ListBehavior:
- Usage
<ListBox controls:ListBehavior.ItemDoubleClickedCommand="{Binding ItemDoubleClickedCommand}" controls:ListBehavior.ItemClickedCommand="{Binding ItemClickedCommand}" controls:ListBehavior.EmptyAreaDoubleClickCommand="{Binding EmptyAreaDoubleClickCommand}" controls:ListBehavior.EmptyAreaDoubleClickCommandParameter="Parameter" controls:ListBehavior.EmptyAreaClickCommand="{Binding EmptyAreaClickCommand}" controls:ListBehavior.EmptyAreaClickCommandParameter="Parameter" controls:ListBehavior.AutoDeselect="True" />
ScrollBehavior:
- Usage
<ListBox ItemsSource="{Binding LogEntries}" controls:ScrollBehavior.AutoScrollToLast="True" /> <ListBox ItemsSource="{Binding LogEntries}" controls:ScrollBehavior.ScrollToItem="{Binding ImportantEntry}" />
TextBoxBehavior:
- Usage
<TextBox Text="{Binding TheText}" controls:TextBoxBehavior.SelectAllOnFocus="True" controls:TextBoxBehavior.SelectedText="{Binding SelectedText}" />
WindowBehavior:
- Usage
<Window controls:WindowBehavior.ClosingCommand="{Binding ClosingCommand}"> <Button Content="Close" controls:WindowBehavior.DialogResult="True" /> <Button Content="Try Close" controls:WindowBehavior.DialogResultCommand="{Binding TryCloseCommand}" /> </Window>
public class MainViewModel : ObservableObject { public MainViewModel() { TryCloseCommand = new DelegateCommand<WindowClosingArgs>(TryClose); } public DelegateCommand<WindowClosingArgs> TryCloseCommand { get; private set; } private void TryClose(WindowClosingArgs e) { // Ask user if really close e.Cancel = true; //e.DialogResult = false; } }
WindowTitleBarBehavior:
- Usage
<Window controls:WindowTitleBarBehavior.DisableMinimizeButton="True" controls:WindowTitleBarBehavior.DisableMaximizeButton="True" controls:WindowTitleBarBehavior.DisableSystemMenu="True"> </Window>
Links
License
Copyright (c) David Wendland. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for full license information.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-windows7.0 is compatible. net9.0-windows7.0 is compatible. |
-
net8.0-windows7.0
- Chapter.Net.WPF.Theming (>= 2.2.0)
-
net9.0-windows7.0
- Chapter.Net.WPF.Theming (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.