Skip to content

Commit

Permalink
Add tooltip update logic and new button in MenusView
Browse files Browse the repository at this point in the history
Added OnContentChangedCallback to handle ContentTemplateProperty changes, ensuring tooltips update accordingly. Introduced private UpdateTooltip method to encapsulate tooltip logic. Modified ContentTemplateProperty to include OnContentChangedCallback. Added a new Button in MenusView.xaml with a custom tooltip using ToolTipAssist properties.
  • Loading branch information
Stéphane ANDRE (E104915) committed Oct 17, 2024
1 parent aada09a commit 4fccf03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/MyNet.Wpf/Parameters/ToolTipAssist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ private static void OnContentChangedCallback(DependencyObject d, DependencyPrope
if (d is not FrameworkElement target) return;
if (e.NewValue is null) return;

UpdateTooltip(target);
}

private static void UpdateTooltip(FrameworkElement target)
{
var placementMode = GetPlacementMode(target);
var tooltip = new ToolTip
{
Content = new ContentControl()
{
Content = e.NewValue,
ContentTemplate = GetContentTemplate(target)
},
Content = GetContent(target),
ContentTemplate = GetContentTemplate(target),
Placement = placementMode.HasValue ? PlacementMode.Custom : PlacementMode.Mouse,
};
target.ToolTip = tooltip;
Expand All @@ -54,7 +56,7 @@ private static void OnContentChangedCallback(DependencyObject d, DependencyPrope
"ContentTemplate",
typeof(DataTemplate),
typeof(ToolTipAssist),
new PropertyMetadata(null));
new PropertyMetadata(null, OnContentChangedCallback));

public static DataTemplate GetContentTemplate(UIElement item) => (DataTemplate)item.GetValue(ContentTemplateProperty);

Expand Down
10 changes: 10 additions & 0 deletions src/tests/MyNet.Wpf.TestApp/Views/MenusView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
ToolTipService.ShowOnDisabled="True"
ToolTipService.ShowsToolTipOnKeyboardFocus="True" />
</smtx:XamlDisplay>

<smtx:XamlDisplay UniqueKey="m_3_0_0">
<Button my:ToolTipAssist.PlacementMode="{Binding SelectedValue, ElementName=position}" Content="Content Template" my:ToolTipAssist.Content="Cououc">
<my:ToolTipAssist.ContentTemplate>
<DataTemplate>
<contents:SmallContent />
</DataTemplate>
</my:ToolTipAssist.ContentTemplate>
</Button>
</smtx:XamlDisplay>
</my:SimpleStackPanel>
</DockPanel>
</Expander>
Expand Down

0 comments on commit 4fccf03

Please sign in to comment.