forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageButtonTooltipConverter.cs
More file actions
79 lines (71 loc) · 3.51 KB
/
Copy pathImageButtonTooltipConverter.cs
File metadata and controls
79 lines (71 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//-----------------------------------------------------------------------
// <copyright file="ImageButtonToolTipConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <summary>
// Implements ImageButtonToolTipConverter.
// </summary>
//-----------------------------------------------------------------------
namespace Microsoft.PowerShell.Commands.ShowCommandInternal
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Controls;
using System.Windows.Data;
/// <summary>
/// Converts a an ImageButtonBase to its corresponding ToolTip
/// </summary>
[SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes", Justification = "Needed for XAML")]
public class ImageButtonToolTipConverter : IValueConverter
{
// This class is meant to be used like this in XAML:
// <Window xmlns:controls="clr-namespace:Microsoft.PowerShell.Commands.ShowCommandInternal" ...>
// ...
// <Window.Resources>
// <controls:RoutedUICommandToString x:Key="routedUICommandToString"/>
// </Window.Resources>
// ...
// <ContentControl ToolTip="{Binding Path=..., Converter={StaticResource routedUICommandToString}"/>
#region IValueConverter Members
/// <summary>
/// Converts a an ImageButtonBase to its corresponding ToolTip by checking if it has a tooltip property
/// or a command with tooltip text
/// </summary>
/// <param name="value">The ImageButtonBase we are trying to Convert.</param>
/// <param name="targetType"><paramref name="targetType"/> is not used.</param>
/// <param name="parameter"><paramref name="parameter"/> is not used.</param>
/// <param name="culture"><paramref name="culture"/> is not used.</param>
/// <returns>The resulting object obtained from retrieving the property value in <paramref name="parameter"/> (or property values if <paramref name="parameter"/> contains dots) out of <paramref name="value"/>. </returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
ImageButtonBase imageButtonBase = value as ImageButtonBase;
if (imageButtonBase == null)
{
return null;
}
object toolTipObj = imageButtonBase.GetValue(Button.ToolTipProperty);
if (toolTipObj != null)
{
return toolTipObj.ToString();
}
if (imageButtonBase.Command != null && !String.IsNullOrEmpty(imageButtonBase.Command.Text))
{
return imageButtonBase.Command.Text.Replace("_", String.Empty);
}
return null;
}
/// <summary>
/// This method is not supported.
/// </summary>
/// <param name="value"><paramref name="value"/> is not used.</param>
/// <param name="targetType"><paramref name="targetType"/> is not used.</param>
/// <param name="parameter"><paramref name="parameter"/> is not used.</param>
/// <param name="culture"><paramref name="culture"/> is not used.</param>
/// <returns>No value is returned.</returns>
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
#endregion
}
}