Hi,
I have an add-in built with ArcGIS Pro SDK for .NET that displays a formatted multiline text on the ScreenTips of InfoButtons. In order to display the text properly, the width of the ScreenTips is set to Auto so that they get as wide as needed. Up to ArcGIS Pro 3.3, the code below has worked well:
<controls:InfoButton.Resources>
<Style TargetType="{x:Type ribbon:ScreenTip}">
<Setter Property="Width" Value="Auto" />
</Style>
</controls:InfoButton.Resources>
However, the code above doesn't work in 3.4 or later. I noticed that as of 3.4 the ScreenTip in use has changed from the Ribbon namespace (ActiproSoftware.Windows.Controls.Ribbon.Controls.ScreenTip) to the Bars namespace (ActiproSoftware.Windows.Controls.Bars.ScreenTip), and also that a new ProScreenTip class has been added to the SDK. After some research, I was able to produce the following solution:
<controls:InfoButton.Resources>
<Style TargetType="{x:Type controls:ProScreenTip}" BasedOn="{StaticResource {x:Type controls:ProScreenTip}}">
<Setter Property="ComplexContentWidth" Value="500" />
</Style>
</controls:InfoButton.Resources>
However, the solution above requires the library ArcGIS.Desktop.Bars.Wpf.dll to be added as a dependency, meaning that the add-in cannot work in versions of ArcGIS Pro earlier than 3.4. Could you advise if there is a better way to achieve the same?
Also, the value Auto can no longer be used and the ScreenTip doesn't adjust its width to the contents. Are there any alternatives?
Thanks
Solved! Go to Solution.
My only thought was to hack in in via code behind.
public partial class Dockpane1View : UserControl
{
public Dockpane1View()
{
InitializeComponent();
var assembly = Assembly.GetEntryAssembly();
var version = assembly.GetName().Version; // e.g. 3.4.0.0
var minimumVersion = new Version(3, 4);
if (version > minimumVersion)
Init();
}
private void Init()
{
Type targetType = typeof(ArcGIS.Desktop.Framework.Controls.ProScreenTip);
var baseStyle = Application.Current.TryFindResource(targetType) as Style;
var style = new Style
{
TargetType = targetType,
BasedOn = baseStyle
};
var dpField = targetType.BaseType.GetField("ComplexContentWidthProperty", BindingFlags.Public | BindingFlags.Static);
if (dpField != null)
{
var dp = dpField.GetValue(null) as DependencyProperty;
if (dp != null)
{
Setter setter = new Setter(dp, -1.0);
style.Setters.Add(setter);
// push the style into the control itself or somewhere higher
// here i'm pushing into the dockpane, could do at app level instead
this.Resources[targetType] = style;
}
}
}
}
I have been able to figure out how to automatically adjust the width of a ProScreenTip to its contents.
<controls:InfoButton.Resources>
<Style TargetType="{x:Type controls:ProScreenTip}" BasedOn="{StaticResource {x:Type controls:ProScreenTip}}">
<Setter Property="ComplexContentWidth" Value="-1" />
</Style>
</controls:InfoButton.Resources>
However, the other question remains. The solution above requires the assembly ArcGIS.Desktop.Bars.Wpf.dll to be added as a dependency to the add-in, making it incompatible with ArcGIS Pro 3.3 or earlier. Are there any alternatives?
Hi @ljlopez
In 3.3, are you using the ArcGIS.Desktop.Framework.Controls.InfoButton? Can you please give me a little more of the xaml code snippet as to how you have sited this control in your dockpane?
Thanks!
Hi @UmaHarano. Thanks for your answer. Yes, I am using Esri's InfoButton. In 3.3, the code would be
<controls:InfoButton Header="MyHeader" Description="MyDescription">
<controls:InfoButton.Resources>
<Style TargetType="{x:Type ribbon:ScreenTip}">
<Setter Property="Width" Value="Auto" />
</Style>
</controls:InfoButton.Resources>
</controls:InfoButton>
where
xmlns:controls="clr-namespace:ArcGIS.Desktop.Framework.Controls;assembly=ArcGIS.Desktop.Framework"
xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
That customizes the ScreenTip so that its width gets bigger or smaller depending on the length of the description. However, in 3.4 you would need the code of my previous comment, and that requires the assembly ArcGIS.Desktop.Bars.Wpf.dll to be added as a dependency, but that assembly is not included in 3.3 and the add-in fails to render.
3.3 is using the class ActiproSoftware.Windows.Controls.Ribbon.Controls.ScreenTip included in the assembly ArcGIS.Desktop.Ribbon.Wpf.dll, while 3.4 is ultimately using the class ActiproSoftware.Windows.Controls.Bars.ScreenTip included in the assembly ArcGIS.Desktop.Bars.Wpf.dll.
I tried loading these InfoButton resources conditionally based on the ArcGIS Pro version, but that didn't help. If the dependency ArcGIS.Desktop.Bars.Wpf.dll is included, then the add-in doesn't render in 3.3.
My only thought was to hack in in via code behind.
public partial class Dockpane1View : UserControl
{
public Dockpane1View()
{
InitializeComponent();
var assembly = Assembly.GetEntryAssembly();
var version = assembly.GetName().Version; // e.g. 3.4.0.0
var minimumVersion = new Version(3, 4);
if (version > minimumVersion)
Init();
}
private void Init()
{
Type targetType = typeof(ArcGIS.Desktop.Framework.Controls.ProScreenTip);
var baseStyle = Application.Current.TryFindResource(targetType) as Style;
var style = new Style
{
TargetType = targetType,
BasedOn = baseStyle
};
var dpField = targetType.BaseType.GetField("ComplexContentWidthProperty", BindingFlags.Public | BindingFlags.Static);
if (dpField != null)
{
var dp = dpField.GetValue(null) as DependencyProperty;
if (dp != null)
{
Setter setter = new Setter(dp, -1.0);
style.Setters.Add(setter);
// push the style into the control itself or somewhere higher
// here i'm pushing into the dockpane, could do at app level instead
this.Resources[targetType] = style;
}
}
}
}