-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39b8a00
commit 4df4258
Showing
11 changed files
with
374 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="CodeSculpt.Wpf.Sample.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:CodeSculpt.Wpf.Sample" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
namespace CodeSculpt.Wpf.Sample; | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
23 changes: 23 additions & 0 deletions
23
samples/CodeSculpt.Wpf.Sample/CodeSculpt.Wpf.Sample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UseWPF>true</UseWPF> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\CodeSculpt.Wpf\CodeSculpt.Wpf.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Views\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Window x:Class="CodeSculpt.Wpf.Sample.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:Attached="clr-namespace:CodeSculpt.Wpf.AttachedProperties;assembly=CodeSculpt.Wpf" | ||
xmlns:vm="clr-namespace:CodeSculpt.Wpf.Sample.ViewModels" | ||
xmlns:local="clr-namespace:CodeSculpt.Wpf.Sample" | ||
mc:Ignorable="d" | ||
Title="MainWindow" | ||
Height="450" | ||
Width="800"> | ||
<Window.DataContext> | ||
<vm:MainViewModel /> | ||
</Window.DataContext> | ||
<StackPanel> | ||
<TextBox Attached:TextBoxProperties.IsNumericOnly="True" | ||
Attached:TextBoxProperties.OnEnterKeyDown="{Binding TextBoxCommand}" /> | ||
|
||
|
||
<Button Content="Button with tooltip test" | ||
ToolTip="Ciaooo" | ||
IsEnabled="{Binding ElementName=disableButton, Path=IsChecked}" | ||
Attached:ButtonProperties.DisabledToolTip="asdasd" /> | ||
|
||
<CheckBox x:Name="disableButton" /> | ||
</StackPanel> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Windows; | ||
|
||
namespace CodeSculpt.Wpf.Sample; | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
|
||
namespace CodeSculpt.Wpf.Sample.ViewModels; | ||
|
||
public partial class MainViewModel : ObservableObject | ||
{ | ||
public MainViewModel() | ||
{ | ||
TextBoxCommand = new RelayCommand(() => | ||
{ | ||
// Command logic | ||
a = true; | ||
}); | ||
} | ||
|
||
public RelayCommand TextBoxCommand { get; } | ||
|
||
[ObservableProperty] | ||
private bool a; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace CodeSculpt.Wpf.AttachedProperties; | ||
public class ButtonProperties : DependencyObject | ||
{ | ||
#region DisableToolTip | ||
|
||
private static readonly DependencyPropertyKey originalToolTipPropertyKey = DependencyProperty.RegisterAttachedReadOnly("OriginalToolTip", typeof(string), typeof(ButtonProperties), new FrameworkPropertyMetadata(default(string))); | ||
|
||
/// <summary> | ||
/// Contains the original Button.ToolTip value to display when the Button.IsEnabled property value is set to true. | ||
/// </summary> | ||
public static readonly DependencyProperty OriginalToolTipProperty = originalToolTipPropertyKey.DependencyProperty; | ||
|
||
/// <summary> | ||
/// Gets the value of the OriginalToolTip property. | ||
/// </summary> | ||
/// <param name="dependencyObject">The DependencyObject to return the OriginalToolTip property value from.</param> | ||
/// <returns>The value of the OriginalToolTip property.</returns> | ||
public static string GetOriginalToolTip(DependencyObject dependencyObject) => (string)dependencyObject.GetValue(OriginalToolTipProperty); | ||
|
||
/// <summary> | ||
/// Provides Button controls with an additional tool tip property that only displays when the Button.IsEnabled property value is set to false. | ||
/// </summary> | ||
public static readonly DependencyProperty DisabledToolTipProperty = DependencyProperty.RegisterAttached("DisabledToolTip", typeof(string), typeof(ButtonProperties), new UIPropertyMetadata(string.Empty, OnDisabledToolTipChanged)); | ||
|
||
/// <summary> | ||
/// Gets the value of the DisabledToolTip property. | ||
/// </summary> | ||
/// <param name="dependencyObject">The DependencyObject to return the DisabledToolTip property value from.</param> | ||
/// <returns>The value of the DisabledToolTip property.</returns> | ||
public static string GetDisabledToolTip(DependencyObject dependencyObject) => (string)dependencyObject.GetValue(DisabledToolTipProperty); | ||
|
||
/// <summary> | ||
/// Sets the value of the DisabledToolTip property. | ||
/// </summary> | ||
/// <param name="dependencyObject">The DependencyObject to set the DisabledToolTip property value of.</param> | ||
/// <param name="value">The value to be assigned to the DisabledToolTip property.</param> | ||
public static void SetDisabledToolTip(DependencyObject dependencyObject, string value) => dependencyObject.SetValue(DisabledToolTipProperty, value); | ||
|
||
private static void OnDisabledToolTipChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var button = dependencyObject as Button; | ||
ToolTipService.SetShowOnDisabled(button, true); | ||
var oldValue = e.OldValue as string; | ||
var newValue = e.NewValue as string; | ||
|
||
if (oldValue!.Length == 0 && newValue!.Length > 0) | ||
{ | ||
button!.IsEnabledChanged += Button_IsEnabledChanged; | ||
} | ||
else if (oldValue.Length > 0 && newValue!.Length == 0) | ||
{ | ||
button!.IsEnabledChanged -= Button_IsEnabledChanged; | ||
} | ||
} | ||
|
||
private static void Button_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var button = sender as Button; | ||
|
||
if (GetOriginalToolTip(button!) == null) | ||
{ | ||
button!.SetValue(originalToolTipPropertyKey, button.ToolTip.ToString()); | ||
} | ||
|
||
button!.ToolTip = (bool)e.NewValue ? GetOriginalToolTip(button!) : GetDisabledToolTip(button!); | ||
} | ||
|
||
#endregion | ||
} |
Oops, something went wrong.